This repository has been archived by the owner on Mar 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
/
sync-gateway-config.json
63 lines (58 loc) · 1.75 KB
/
sync-gateway-config.json
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
{
"log": ["*"],
"facebook": { "register": true },
"databases": {
"todolite": {
"server": "walrus:",
"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" || (doc._deleted && oldDoc && oldDoc.type == "list")) {
// Make sure that the owner propery exists:
var owner = oldDoc ? oldDoc.owner : doc.owner;
if (!owner) {
throw({forbidden : "List must have an owner."});
}
// Make sure that only the owner of the list can update the list:
if (doc.owner && owner != doc.owner) {
throw({forbidden : "Cannot change owner for lists."});
}
var ownerName = owner.substring(owner.indexOf(":")+1);
requireUser(ownerName);
var ch = "list-"+doc._id;
if (!doc._deleted) {
channel(ch);
}
// Grant owner access to the channel:
access(ownerName, ch);
// Grant shared members access to the channel:
var members = !doc._deleted ? doc.members : oldDoc.members;
if (Array.isArray(members)) {
var memberNames = [];
for (var i = members.length - 1; i >= 0; i--) {
memberNames.push(members[i].substring(members[i].indexOf(":")+1))
};
access(memberNames, ch);
}
} 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");
}
}
`
}
}
}