Skip to content

Instantly share code, notes, and snippets.

@ArihantRk
Created August 18, 2016 13:42
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 ArihantRk/f6d26a15e1664106a1632b087b5f15f6 to your computer and use it in GitHub Desktop.
Save ArihantRk/f6d26a15e1664106a1632b087b5f15f6 to your computer and use it in GitHub Desktop.
sync_config.json
"server": "http://cbsnode:8091",
"bucket": "ptxdata",
"revs_limit": 5,
"sync": 'function(doc, oldDoc) {
/* Generic document Validations */
/* Rules: [1] */
if ((!doc._deleted) && ((!doc.type) || (!doc.ver))) {
throw ({
forbidden: "missing mandatory attributes 'type' or 'ver'."
});
}
/* Case: Document Create */
if ((oldDoc == null) || ((oldDoc != null) && (oldDoc._deleted))) {
/* Rules: [6] */
if ((doc.readers) || (doc.writers) || (doc.owners) || (doc.channels) || (doc.accessCH)) {
requireRole("level-3");
} else if (doc.type == "ptxaccess") {
requireRole("level-3");
} else {
/* Rules: [5] */
requireRole(["level-2"]);
}
}
/* Case: Document Update */
else if ((!doc._deleted) && (oldDoc != null) && (!oldDoc._deleted)) {
/* Rules: [6] */
if (((!oldDoc.readers) && (doc.readers)) || ((!oldDoc.writers) && (doc.writers)) || ((!oldDoc.owners) && (doc.owners)) || ((!oldDoc.channels) && (doc.channels)) || ((!oldDoc.accessCH) && (doc.accessCH)) || ((!oldDoc.metaReaders) && (doc.metaReaders)) || ((!oldDoc.accessMetaCH) && (doc.accessMetaCH)) || ((!oldDoc.attachmentReaders) && (doc.attachmentReaders)) || ((!oldDoc.accessAttachmentCH) && (doc.accessAttachmentCH))) {
requireRole("level-3");
} else if (((oldDoc.readers) && (!doc.readers)) || ((oldDoc.writers) && (!doc.writers)) || ((oldDoc.owners) && (!doc.owners)) || ((oldDoc.channels) && (!doc.channels)) || ((oldDoc.accessCH) && (!doc.accessCH)) || ((oldDoc.metaReaders) && (!doc.metaReaders)) || ((oldDoc.accessMetaCH) && (!doc.accessMetaCH)) || ((oldDoc.attachmentReaders) && (!doc.attachmentReaders)) || ((oldDoc.accessAttachmentCH) && (!doc.accessAttachmentCH))) {
requireRole("level-3");
} else if (((oldDoc.readers) && (doc.readers.toString() != oldDoc.readers.toString())) || ((oldDoc.writers) && (doc.writers.toString() != oldDoc.writers.toString())) || ((oldDoc.owners) && (doc.owners.toString() != oldDoc.owners.toString())) || ((oldDoc.channels) && (doc.channels.toString() != oldDoc.channels.toString())) || ((oldDoc.accessCH) && (doc.accessCH.toString() != oldDoc.accessCH.toString())) || ((oldDoc.metaReaders) && (doc.metaReaders.toString() != oldDoc.metaReaders.toString())) || ((oldDoc.accessMetaCH) && (doc.accessMetaCH.toString() != oldDoc.accessMetaCH.toString())) || ((oldDoc.attachmentReaders) && (doc.attachmentReaders.toString() != oldDoc.attachmentReaders.toString())) || ((oldDoc.accessAttachmentCH) && (doc.accessAttachmentCH.toString() != oldDoc.accessAttachmentCH.toString()))) {
requireRole("level-3");
} else if (doc.type == "ptxaccess") {
requireRole("level-3");
} else {
/* Rules: [8] */
requireRole(["level-2"]);
if (oldDoc.writers) {
requireUser(oldDoc.writers);
}
}
}
/* Case: Document delete */
else if (doc._deleted) {
/* Rules: [9] */
requireRole(["level-2"]);
if ((oldDoc) && (oldDoc.owners)) {
/* Rules: [9] */
requireUser(oldDoc.owners);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment