Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Support erica pushes.
Browse files Browse the repository at this point in the history
Now the config will be stored in either couchapp/kanso root property,
but underneath is the same.
  • Loading branch information
ryanramage committed Oct 18, 2012
1 parent d45ead1 commit a25f148
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 58 deletions.
10 changes: 6 additions & 4 deletions lib/shows.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,17 @@ exports.kanso_details = function(doc, req) {
db_path = req.info.db_name + '/_design/market/_rewrite/_db';
}

var meta = doc.couchapp || doc.kanso;

return jsonp.response(req.query.callback, {
kanso: doc.kanso,
kanso: meta,
open_path: utils.open_path(doc),
style : 'design-doc', /* option for db to replicate whole db */
db_src : utils.app_db(req, db_path),
doc_id : doc._id,
icon_url : utils.app_db(req, db_path) + '/' + doc._id + '/' + doc.kanso.config.icons['96'],
user_url : utils.user_url(req, doc.kanso.pushed_by),
user : doc.kanso.pushed_by,
icon_url : utils.app_db(req, db_path) + '/' + doc._id + '/' + meta.config.icons['96'],
user_url : utils.user_url(req, meta.pushed_by),
user : meta.pushed_by,
db_path : db_path,
requested_path :req.requested_path
});
Expand Down
5 changes: 3 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ exports.flattr_url = function(req, id) {


exports.open_path = function (doc) {
if (doc.kanso.index) {
var meta = doc.couchapp || doc.kanso;
if (meta.index) {
return doc.kanso.index;
}
if (doc.kanso.baseURL) {
if (meta.baseURL) {
return doc.kanso.baseURL + '/';
}
if (doc.rewrites && doc.rewrites.length) {
Expand Down
76 changes: 39 additions & 37 deletions lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,90 +8,92 @@ module.exports = function (newDoc, oldDoc, userCtx) {
return;
}
}
if (userCtx.name !== oldDoc.kanso.pushed_by) {
var old_meta = oldDoc.couchapp || oldDoc.kanso;
if (userCtx.name !== old_meta.pushed_by) {
throw {
unauthorized: 'Only the uploader can delete an existing app'
};
}
// don't need to further validate a deleted document!
return;
}
var manifest = newDoc.couchapp || newDoc.kanso;
// updating
if (oldDoc && !newDoc._deleted) {
if (newDoc.kanso.pushed_by !== oldDoc.kanso.pushed_by) {
if (manifest.pushed_by !== manifest.pushed_by) {
throw {
unauthorized: 'Only the uploader can update an existing app'
};
}
}

// TODO: check for other doc types here like comments etc
if (!newDoc.type && !newDoc.kanso) {
if (!newDoc.type && !manifest) {
throw {
forbidden: 'Document is missing "kanso" property\n' +
'Adding apps requires at least kanso 0.1.4'
forbidden: 'Document is missing "kanso" or "couchapp" property\n' +
'Adding apps requires at least kanso 0.1.4 or erica 2.0'
};
}

if (newDoc.kanso) {
if (manifest) {
if (!userCtx.name) {
throw {unauthorized: 'You must be logged in to upload an app'};
}
if (!newDoc.kanso.pushed_by) {
throw {forbidden: 'Missing kanso.pushed_by property'};
if (!manifest.pushed_by) {
throw {forbidden: 'Manifest missing pushed_by property'};
}
if (!newDoc.kanso.push_time) {
throw {forbidden: 'Missing kanso.push_dtime property'};
if (!manifest.push_time) {
throw {forbidden: 'Manifest missing push_time property'};
}
if (!newDoc.kanso.build_time) {
throw {forbidden: 'Missing kanso.build_time property'};
if (!manifest.build_time) {
throw {forbidden: 'Manifest missing build_time property'};
}
if (!newDoc.kanso.config) {
throw {forbidden: 'Missing kanso.config property'};
if (!manifest.config) {
throw {forbidden: 'Manifest missing config property'};
}
if (!newDoc.kanso.config.name) {
throw {forbidden: 'Missing kanso.config.name property'};
if (!manifest.config.name) {
throw {forbidden: 'Manifest missing config.name property'};
}
if (!newDoc.kanso.config.description) {
throw {forbidden: 'Missing kanso.config.description property'};
if (!manifest.config.description) {
throw {forbidden: 'Manifest missing config.description property'};
}
if (!newDoc.kanso.config.long_description) {
throw {forbidden: 'Missing kanso.config.long_description property'};
if (!manifest.config.long_description) {
throw {forbidden: 'Manifest missing config.long_description property'};
}
if (!newDoc.kanso.config.version) {
throw {forbidden: 'Missing kanso.config.version property'};
if (!manifest.config.version) {
throw {forbidden: 'Manifest missing config.version property'};
}
if (!newDoc.kanso.config.screenshots) {
throw {forbidden: 'Missing kanso.config.screenshots property'};
if (!manifest.config.screenshots) {
throw {forbidden: 'Manifest missing config.screenshots property'};
}
if (!newDoc.kanso.config.screenshots.length) {
if (!manifest.config.screenshots.length) {
throw {forbidden: 'You must provide at least one screenshot'};
}
if (!newDoc.kanso.config.promo_images) {
throw {forbidden: 'Missing kanso.config.promo_images property'};
if (!manifest.config.promo_images) {
throw {forbidden: 'Missing config.promo_images property'};
}
if (!newDoc.kanso.config.icons) {
throw {forbidden: 'Missing kanso.config.icons property'};
if (!manifest.config.icons) {
throw {forbidden: 'Missing config.icons property'};
}
if (!newDoc.kanso.config.icons['16']) {
if (!manifest.config.icons['16']) {
throw {forbidden: 'Missing 16x16 icon'};
}
if (!newDoc.kanso.config.icons['48']) {
if (!manifest.config.icons['48']) {
throw {forbidden: 'Missing 48x48 icon'};
}
if (!newDoc.kanso.config.icons['96']) {
if (!manifest.config.icons['96']) {
throw {forbidden: 'Missing 96x96 icon'};
}
if (!newDoc.kanso.config.icons['128']) {
if (!manifest.config.icons['128']) {
throw {forbidden: 'Missing 128x128 icon'};
}
if (!newDoc.kanso.config.promo_images.small) {
if (!manifest.config.promo_images.small) {
throw {forbidden: 'You must provide at least a small promo image'};
}
if (!newDoc.kanso.config.categories) {
throw {forbidden: 'Missing property kanso.config.categories'};
if (!manifest.config.categories) {
throw {forbidden: 'Missing property config.categories'};
}
if (!newDoc.kanso.config.categories.length) {
if (!manifest.config.categories.length) {
throw {forbidden: 'You must provide at least one category'};
}

Expand Down
34 changes: 19 additions & 15 deletions lib/views.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
exports.apps = {
map: function (doc) {
if (!/^_design\//.test(doc._id) && doc.kanso) {
emit([doc._id], doc.kanso);
var meta = doc.couchapp || doc.kanso;
if (!/^_design\//.test(doc._id) && meta) {
emit([doc._id], meta);
}
}
};

exports.apps_by_category = {
map: function (doc) {
if (!/^_design\//.test(doc._id) && doc.kanso) {
var cfg = doc.kanso.config;
var meta = doc.couchapp || doc.kanso;
if (!/^_design\//.test(doc._id) && meta) {
var cfg = meta.config;
if (cfg.categories && cfg.categories.length) {
for (var i = 0; i < cfg.categories.length; i++) {
emit([cfg.categories[i]], doc.kanso);
emit([cfg.categories[i]], meta);
}
}
else {
emit(['uncategorized'], doc.kanso);
emit(['uncategorized'], meta);
}
emit('total', 1);
}
Expand All @@ -31,8 +33,9 @@ exports.apps_by_category = {

exports.apps_by_user = {
map: function (doc) {
if (!/^_design\//.test(doc._id) && doc.kanso) {
emit([doc.kanso.pushed_by], doc.kanso);
var meta = doc.couchapp || doc.kanso;
if (!/^_design\//.test(doc._id) && meta) {
emit([meta.pushed_by], meta);
}
}
};
Expand All @@ -47,7 +50,8 @@ exports.hosting = {

exports.keyword_search = {
map : function(doc) {
if (!doc.kanso || !doc.kanso.config) return;
var meta = doc.couchapp || doc.kanso;
if (!meta || !meta.config) return;
var Tokenizer = require('views/lib/tokenizer');
var _ = require('views/lib/underscore')._;

Expand All @@ -66,21 +70,21 @@ exports.keyword_search = {


var tokenizer = new Tokenizer();
var meta = doc.kanso.config;
var id_tokens = tokenizer.tokenize(meta.name);
var config = meta.config;
var id_tokens = tokenizer.tokenize(config.name);
var id_map = filter_junk(id_tokens);

var desc_tokens = tokenizer.tokenize(meta.description);
var desc_tokens = tokenizer.tokenize(config.description);
var desc_map = filter_junk(desc_tokens);


var long_description_tokens = tokenizer.tokenize(meta.long_description);
var long_description_tokens = tokenizer.tokenize(config.long_description);
var l_desc_map = filter_junk(long_description_tokens);

var keywords = _.union(id_map, desc_map, l_desc_map);

var icon = meta.icons["96"];
var by = doc.kanso.pushed_by;
var icon = config.icons["96"];
var by = meta.pushed_by;


_.each(keywords, function(token){
Expand Down

0 comments on commit a25f148

Please sign in to comment.