-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcouchbase-sync-gateway.js
More file actions
39 lines (36 loc) · 1.08 KB
/
Copy pathcouchbase-sync-gateway.js
File metadata and controls
39 lines (36 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function (doc, oldDoc) {
if (doc._deleted) {
requireRole("admin");
// skip other validation because a deletion has no other properties
return;
}
// main documents, only to be edited by admins
if ("main" == doc.type || "media" == doc.type || "category" == doc.type) {
requireRole("admin");
if ("main" == doc.type) {
if (!doc.key || !doc.localizations || !doc.tags || 0 == doc.tags.length) {
throw({forbidden: "Invalid main document, must have 'key', 'localizations' and at least one tag in 'tags'"})
}
}
channel("public");
}
// suggestion document, everybody can create these and has access to the ones created by themselves
else if ("suggestion" == doc.type) {
if (!doc.author) {
throw({forbidden: "Must have author"})
}
var sugg_channel = "suggestion-" + doc.author;
if (!oldDoc) {
requireUser(doc.author);
access(doc.author, sugg_channel);
channel("admin", sugg_channel);
}
else {
requireAccess(["admin", sugg_channel]);
}
}
// unknown document type
else {
throw({forbidden: "Document type '" + doc.type + "' not permitted"});
}
}