forked from chat-sdk/chat-sdk-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rules.json
257 lines (197 loc) · 8.75 KB
/
rules.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
{
"rules": {
//".read": true,
//".write": "auth != null",
//".read": "auth != null",
//".write": "auth != null",
"$root": {
"flagged": {
"threads": {
"$thread_id": {
"messages": {
"$message_id": {
".read": "root.child($root+'/users/'+auth.uid).exists()",
".write":"root.child($root+'/users/'+auth.uid).exists()",
"user-firebase-id":{
".validate": "root.child($root+'/users/'+newData.val()).exists()"
},
"creator-enitity-id": {
".validate": "newData.val() == auth.uid"
}
}
}
}
}
},
"public-threads": {
// Only users who have a profile can create and read
// public threads
".read": "root.child($root+'/users/'+auth.uid).exists()",
".write":"root.child($root+'/users/'+auth.uid).exists()",
"$thread_id": {
}
},
"threads": {
"$thread_id": {
// The user must have a profile to read thread
".read": "root.child($root+'/users/'+auth.uid).exists()",
".write": "root.child($root+'/users/'+auth.uid).exists()",
//".read": "root.child($root+'/threads/'+$thread_id+'/users/'+auth.uid).exists()",
//".write": "root.child($root+'/threads/'+$thread_id+'/users/'+auth.uid).exists()",
"details": {
//"creation-date": {
// This can only be set on creation - the time must be the current time
// ".validate": "data.val() == null && newData.val() == now"
//},
"last-message-added": {
// Can only be set to current time
".validate": "newData.val() == now || data.val() == null"
},
"name": {
// Can only be set on thread creation
".validate": "data.val() == null"
},
"creator-entity-id": {
// Can only be set on thread creation
".validate": "data.val() == null && newData.val() == auth.uid"
},
"type": {
// Legacy type value for backwards compatibility
// 0x0 (0) - Group
// 0x1 (1) - Public
".validate": "data.val() == null && (newData.val() == 0 || newData.val() == 1)"
},
"type_v4": {
// Can only be set on thread creation must be
// 0x1 (1) - Group
// 0x2 (2) - 1to1
// 0x3 (3) - Public
".validate": "data.val() == null && (newData.val() == 1 || newData.val() == 2 || newData.val() == 4)"
}
},
"messages": {
//".validate": "root.child($root+'/threads/'+$thread_id+'/users/'+auth.uid).exists()",
// Only thread members can read and write messages
".read": "root.child($root+'/threads/'+$thread_id+'/users/'+auth.uid).exists()",
".write": "root.child($root+'/threads/'+$thread_id+'/users/'+auth.uid).exists()",
"$message_id": {
"date": {
// Can only be set on message creation, must be current time
".validate": "data.val() == null && newData.val() == now"
},
"payload": {
// Can only be set on message creation
".validate": "data.val() == null"
},
"type": {
// Can only be set on message creation must be 0, 1 or 2
".validate": "data.val() == null && (newData.val() >=0 && newData.val() <= 6)"
},
"user-firebase-id": {
// Can only be set on message creation - a user can only mark a message with their uid
".validate": "data.val() == null && newData.val() == auth.uid"
},
"read": {
}
}
},
"users": {
// For a user to be added to the thread, they should exist in the users area,
".validate": "root.child($root+'/users/'+auth.uid).exists()", //&&
// If this is a public thread, then the user must have an account
// (root.child($root+'/threads/'+$thread_id+'/details/type').val() == 1 &&
// root.child($root+'/users/'+auth.uid).exists()) ||
// If this is a private thread, then only the creator can add a user
// (root.child($root+'/threads/'+$thread_id+'/details/type').val() == 0 &&
// (root.child($root+'/threads/'+$thread_id+'/details/creator-entity-id').val() == auth.uid ||
// root.child($root+'/threads/'+$thread_id+'/users/'+auth.uid).exists()))",
// The user must be a member of the thread to see which users exist
//".read": "root.child($root+'/threads/'+$thread_id+'/users/'+auth.uid).exists()",
// Anyone can add to a public group
// To write to a private group you must be the creator or a member
//".write": "(root.child($root+'/threads/'+$thread_id+'/details/type').val() == 1 &&
// root.child($root+'/users/'+auth.uid).exists()) ||
// (root.child($root+'/threads/'+$thread_id+'/details/type').val() == 0 &&
// (root.child($root+'/threads/'+$thread_id+'/details/creator-entity-id').val() == auth.uid ||
// root.child($root+'/threads/'+$thread_id+'/users/'+auth.uid).exists()))",
"$user_id": {
"name": {
// The user ID should exist
".validate": "root.child($root+'/users/'+auth.uid).exists()"
}
}
}
}
},
"users": {
".read": "root.child($root+'/users/'+auth.uid).exists()",
"$user_id": {
".read": "root.child($root+'/users/'+auth.uid).exists()",
".write": "auth.uid != null",
"authentication-id": {
".validate": "auth.uid == $user_id && newData.val() == auth.uid"
},
"last-online": {
".validate": "auth.uid == $user_id && newData.val() == now"
},
"threads": {
"$thread_id": {
}
}
}
},
"classSearchIndex": {
// Any authenticated user can read the data
".read": "root.child($root+'/users/'+auth.uid).exists()",
// Index the items to improve search performance
".indexOn": ["className", "professor", "semester", "school"],
".write": "auth != null"
//".validate": "auth.email == newData.child('user').val()"
},
"searchIndex": {
// Any authenticated user can read the data
".read": "root.child($root+'/users/'+auth.uid).exists()",
// Index the items to improve search performance
".indexOn": ["name", "email", "phone"],
"$user_id": {
// We can only write to the index related to our user
".write": "$user_id == auth.uid"
}
},
// GeoFire Rules or location based chat
"location": {
// Allow anyone to read the GeoFire index
".read": true,
// Index each location's geohash for faster querying
".indexOn": ["g"],
// Schema validation
"$key": {
// Allow anyone to add, update, or remove keys in the GeoFire index
".write": true,
// Key validation
".validate": "newData.hasChildren(['g', 'l']) && newData.getPriority().length <= 22 && newData.getPriority().length > 0",
// Geohash validation
"g": {
".validate": "newData.val() == newData.parent().getPriority()"
},
// Location coordinates validation
"l": {
"0" : {
".validate": "newData.isNumber() && newData.val() >= -90 && newData.val() <= 90"
},
"1" : {
".validate": "newData.isNumber() && newData.val() >= -180 && newData.val() <= 180"
},
"$other": {
".validate": false
}
},
// Don't allow any other keys to be written
"$other": {
".validate": false
}
}
}
}
}
}