Last active
December 14, 2015 05:28
-
-
Save jchris/5035101 to your computer and use it in GitHub Desktop.
Sync function runs validation and generates access() and channel() maps.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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