forked from googlearchive/friendlypix-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
database-rules.json
231 lines (231 loc) · 8.3 KB
/
database-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
{
"rules": {
// Admin access.
".read": "auth.token.admin === true",
".write": "auth.token.admin === true",
"admins": {
".read": "false", // Only a cloud function or admins can update this.
".write": "false", // Only a cloud function or admins can update this.
"$index": {
"email": {
".validate": "newData.isString()"
}
}
},
// User's personnal feeds.
"feed": {
"$uid": {
".read": "auth.uid === $uid",
".write": "auth.uid === $uid",
"$postId": {
".validate": "newData.val() === true && newData.parent().parent().parent().child('posts').child($postId).exists()"
}
}
},
// List of all Posts.
"posts": {
".read": true,
".indexOn": ["author/uid", "timestamp"], // Allow searching for posts by authors. Useful for deletion.
"$postId": {
".write": "!data.exists() || data.exists() && auth.uid === data.child('author').child('uid').val()", // Allow new writes and allow updates and deletes to own posts.
".validate": "newData.child('author').child('uid').exists() && newData.child('text').exists()",
"text": {
".validate": "newData.isString() && newData.val().length < 2000"
},
"timestamp": {
".validate": "newData.val() === now"
},
"client": {
".validate": "newData.val() === 'web' || newData.val() === 'ios' || newData.val() === 'android'"
},
"sanitized": {
".validate": "false" // Only a cloud function (admin mode) can update this.
},
"moderated": {
".validate": "false" // Only a cloud function (admin mode) can update this.
},
"author": {
"uid": {
".validate": "auth.uid === newData.val()"
},
"full_name": {
".validate": "auth.token.name === newData.val() || (auth.token.name === null && newData.val() === 'Anonymous')"
},
"profile_picture": {
".validate": "true"
}
}
}
},
// Post's comments.
"comments": {
".read": true,
"$postId": {
".indexOn": "author/uid", // Allow searching for comments by authors. Useful for deletion.
".write": "!newData.exists() && auth.uid === root.child('posts').child($postId).child('author').child('uid').val() && !newData.parent().parent().child('posts').child($postId).exists()", // Allow deletes from the post owner
".validate": "root.child('posts').child($postId).exists()", // Check that the post exists
"$commentId": {
".write": "(!data.exists() || data.exists() && auth.uid === data.child('author').child('uid').val()) && (root.child('blocked').child(auth.uid).child(root.child('posts').child($postId).child('author').child('uid').val()).val() !== true)", // Can write new comments and edit/delete particular comment if you are the author.
"text": {
".validate": "newData.isString() && newData.val().length < 2000"
},
"sanitized": {
".validate": "false" // Only a cloud function (admin mode) can update this.
},
"moderated": {
".validate": "false" // Only a cloud function (admin mode) can update this.
},
"timestamp": {
".validate": "newData.val() === now"
},
"author": {
"uid": {
".validate": "auth.uid === newData.val()"
},
"full_name": {
".validate": "auth.token.name === newData.val() || (auth.token.name === null && newData.val() === 'Anonymous')"
},
"profile_picture": {
".validate": "true"
},
"$other": {
".validate": false
}
},
"$other": {
".validate": false
}
}
}
},
// Hashtag index.
"hashtags": {
".read": true,
".write": false
},
// List of post's likes.
"likes": {
".read": true,
"$postId": {
".write": "!newData.exists() && auth.uid === root.child('posts').child($postId).child('author').child('uid').val() && !newData.parent().parent().child('posts').child($postId).exists()", // Allow deletes from the post owner
".validate": "root.child('posts').child($postId).exists()", // Check that the post exists
"$uid": {
".write": "auth.uid === $uid",
".validate": "newData.val() === now"
}
}
},
// List of followers.
"followers": {
".read": true,
"$followedUid": {
"$followerUid": {
".write": "auth.uid === $followerUid", // Can only add yourself as a follower
".validate": "newData.val() === true && newData.parent().parent().parent().child('people').child($followerUid).child('following').child($followedUid).exists()" // Makes sure /people/.../following is in sync
}
}
},
// Public profile information.
"people": {
".indexOn": ["_search_index/full_name", "_search_index/reversed_full_name"],
".read": true,
"$uid": {
".write": "auth.uid === $uid",
"full_name": {
".validate": "auth.token.name === newData.val() || (auth.token.name === null && newData.val() === 'Anonymous')"
},
"profile_picture": {
".validate": "true"
},
"posts": {
"$postId": {
".validate": "newData.val() === true && newData.parent().parent().parent().parent().child('posts').child($postId).exists()"
}
},
"_search_index": {
"full_name": {
".validate": "newData.isString()"
},
"reversed_full_name": {
".validate": "newData.isString()"
}
},
"following": {
"$followedUid": {
".validate": "newData.parent().parent().parent().parent().child('followers').child($followedUid).child($uid).val() === true" // Makes sure /followers is in sync
}
}
}
},
// List of blocked users.
"blocking": {
"$blockerUid": {
".write": "auth.uid === $blockerUid", // Can only add yourself as a blocker
".read": "auth.uid === $blockerUid",
"$blockedUid": {
".read": "auth.uid === $blockedUid",
".validate": "newData.val() === true && newData.parent().parent().parent().child('blocked').child($blockedUid).child($blockerUid).exists()" // Makes sure /blocked is in sync
}
}
},
// List of blocking users.
"blocked": {
"$blockedUid": {
".read": "auth.uid === $blockedUid",
"$blockerUid": {
".read": "auth.uid === $blockerUid",
".write": "auth.uid === $blockerUid", // Can only add yourself as a blocker
".validate": "newData.val() === true && newData.parent().parent().parent().child('blocking').child($blockerUid).child($blockedUid).exists()" // Makes sure /blocker is in sync
}
}
},
// List of flagged posts.
"postFlags": {
"$postId": {
".validate": "root.child('posts').child($postId).exists()", // Check that the post exists
"$uid": {
".write": "auth.uid === $uid",
".read": "auth.uid === $uid",
".validate": "newData.val() === true"
}
}
},
// List of flagged comments.
"commentFlags": {
"$postId": {
".validate": "root.child('posts').child($postId).exists()", // Check that the post exists
"$commentId": {
".validate": "root.child('comments').child($postId).child($commentId).exists()", // Check that the comment exists
"$uid": {
".write": "auth.uid === $uid",
".read": "auth.uid === $uid",
".validate": "newData.val() === true"
}
}
}
},
// Privacy settings
"privacy": {
"$uid": {
".write": "auth.uid === $uid",
".read": "auth.uid === $uid",
"data_processing": {
".validate": "newData.isBoolean()"
},
"content": {
".validate": "newData.isBoolean()"
},
"social": {
".validate": "newData.isBoolean()"
},
"$other": {
".validate": "false"
}
}
},
// Disallow all other attributes.
"$other": {
".validate": false
}
}
}