Permalink
Find file
f204d78 Aug 25, 2016
64 lines (58 sloc) 1.75 KB
{
"log": ["*"],
"facebook": { "register": true },
"databases": {
"todolite": {
"server": "walrus:",
"users": {
"GUEST": {"disabled": true}
},
"sync": `
function(doc, oldDoc) {
// NOTE this function is the same across the iOS, Android, and PhoneGap versions.
if (doc.type == "task") {
if (!doc.list_id) {
throw({forbidden : "Items must have a list_id."});
}
channel("list-"+doc.list_id);
} else if (doc.type == "list" || (doc._deleted && oldDoc && oldDoc.type == "list")) {
// Make sure that the owner propery exists:
var owner = oldDoc ? oldDoc.owner : doc.owner;
if (!owner) {
throw({forbidden : "List must have an owner."});
}
// Make sure that only the owner of the list can update the list:
if (doc.owner && owner != doc.owner) {
throw({forbidden : "Cannot change owner for lists."});
}
var ownerName = owner.substring(owner.indexOf(":")+1);
requireUser(ownerName);
var ch = "list-"+doc._id;
if (!doc._deleted) {
channel(ch);
}
// Grant owner access to the channel:
access(ownerName, ch);
// Grant shared members access to the channel:
var members = !doc._deleted ? doc.members : oldDoc.members;
if (Array.isArray(members)) {
var memberNames = [];
for (var i = members.length - 1; i >= 0; i--) {
memberNames.push(members[i].substring(members[i].indexOf(":")+1))
};
access(memberNames, ch);
}
} else if (doc.type == "profile") {
channel("profiles");
var user = doc._id.substring(doc._id.indexOf(":")+1);
if (user !== doc.user_id) {
throw({forbidden : "Profile user_id must match docid."});
}
requireUser(user);
access(user, "profiles");
}
}
`
}
}
}