-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.rules.json
More file actions
97 lines (97 loc) · 3.9 KB
/
database.rules.json
File metadata and controls
97 lines (97 loc) · 3.9 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
{
"rules": {
".read": "auth != null",
// ".write": "auth != null",
"emotions": {
".indexOn": "channel",
"$emotion_id": {
".write": "!data.exists() && newData.exists()",
".validate": "newData.hasChildren(['createdOn', 'uid', 'channel', 'emotion'])",
"createdOn": {
".validate": "newData.val() <= now && (!root.child('lastEmotion').child(auth.uid).exists() || newData.val() > (root.child('lastEmotion').child(auth.uid).val() + 5000))"
},
"uid": {
".validate": "newData.isString() && newData.val().length > 0 && newData.val() === auth.uid"
},
"channel": {
".validate": "newData.isString() && newData.val().length > 0 && newData.val().length < 20"
},
"emotion": {
".validate": "newData.isString() && newData.val().length > 0 && newData.val().length < 256"
},
"$other": { ".validate": false }
}
},
"lastEmotion": {
"$user_id": {
".write": "$user_id === auth.uid",
".validate": "newData.val() <= now"
}
},
"messages": {
".indexOn": ["channel", "replyCount"],
"$message_id": {
".write": "newData.exists()",
".validate": "newData.hasChildren(['channel', 'content', 'createdOn', 'replyCount', 'uid', 'upboats', 'updatedOn']) && newData.child('createdOn').val() <= newData.child('updatedOn').val()",
"channel": {
".validate": "newData.isString() && newData.val().length > 0 && newData.val().length < 20"
},
"content": {
".validate": "newData.isString() && newData.val().length > 0 && newData.val().length < 256"
},
"createdOn": {
".validate": "newData.val() <= now && (data.exists() || (newData.val() === newData.parent().parent().parent().child('last_message/'+auth.uid).val()))"
},
"updatedOn": {
".validate": "newData.val() <= now"
},
"replyCount": {
".validate": "newData.isNumber() && newData.val() >= 0 && ((!data.exists() && newData.val() === 0) || (newData.val() === data.val() + 1 || newData.val() === data.val()))"
},
"upboats": {
".validate": "newData.isNumber() && ((!data.exists() && newData.val() === 1) || (newData.val() === (data.val() + 1) || newData.val() === (data.val() - 1) || newData.val() === data.val()))"
},
"uid": {
".validate": "newData.isString() && newData.val().length > 0"
},
"updatedBy": {
".validate": "newData.isString() && newData.val().length > 0 && newData.val() === auth.uid"
},
"$other": { ".validate": false }
}
},
"last_message": {
"$user": {
// timestamp can't be deleted or I could just recreate it to bypass our throttle
".write": "newData.exists() && auth.uid === $user",
// the new value must be at least 5000 milliseconds after the last (no more than one message every five seconds)
// the new value must be before now (it will be since `now` is when it reaches the server unless I try to cheat)
".validate": "newData.isNumber() && newData.val() === now && (!data.exists() || newData.val() > data.val()+3000)"
}
},
"swarm": {
"$message_id": {
".write": "newData.exists() && (!data.exists() || root.child('messages').child($message_id).exists())",
"$user_id": {
".validate": "newData.isString() && newData.val().length > 0 && newData.val().length < 256 && $user_id === auth.uid"
}
}
},
"userUpboats": {
"$channel": {
"$user_id": {
"$message_id": {
".write": "$user_id === auth.uid"
}
}
}
},
"presence": {
".indexOn": ".value",
"$presence_id": {
".write": "auth != null",
".validate": "newData.isString()"
}
}
}
}