Skip to content

Instantly share code, notes, and snippets.

@tleyden
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tleyden/ca063725e6158eca4093 to your computer and use it in GitHub Desktop.
Save tleyden/ca063725e6158eca4093 to your computer and use it in GitHub Desktop.
{
"log": ["CRUD", "REST+", "Access"],
"facebook": { "register": true },
"databases": {
"todos": {
"server":"http://{{ .COUCHBASE_SERVER_IP }}:8091",
"bucket":"todos",
"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") {
channel("list-"+doc._id);
if (!doc.owner) {
throw({forbidden : "list must have an owner"})
}
if (oldDoc) {
var oldOwnerName = oldDoc.owner.substring(oldDoc.owner.indexOf(":")+1);
requireUser(oldOwnerName)
}
var ownerName = doc.owner.substring(doc.owner.indexOf(":")+1);
access(ownerName, "list-"+doc._id);
if (Array.isArray(doc.members)) {
var memberNames = [];
for (var i = doc.members.length - 1; i >= 0; i--) {
memberNames.push(doc.members[i].substring(doc.members[i].indexOf(":")+1))
};
access(memberNames, "list-"+doc._id);
}
} 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"); // TODO this should use roles
}
}
`
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment