Skip to content

Instantly share code, notes, and snippets.

@jchris
Last active December 14, 2015 05:28
Show Gist options
  • Save jchris/5035101 to your computer and use it in GitHub Desktop.
Save jchris/5035101 to your computer and use it in GitHub Desktop.
Sync function runs validation and generates access() and channel() maps.
config.sync = function(doc, oldDoc, userCtx, secObj) {
if (doc.channel_id) {
// doc belongs to a channel
channel("ch-"+doc.channel_id);
// this document describes a channel
if (doc.channel_id == doc._id) {
// magic document, treat it carefully
if (oldDoc && oldDoc.owners.indexOf(userCtx.name) === -1) {
throw({unauthorized:"you are not a channel owner"});
}
// grants access to the channel to all members and owners
access(doc.owners, "ch-"+doc._id);
access(doc.members, "ch-"+doc._id);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment