-
Notifications
You must be signed in to change notification settings - Fork 1
/
firestore.rules
41 lines (41 loc) · 1.28 KB
/
firestore.rules
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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isAdmin(userId) {
return get(/databases/$(database)/documents/users/$(userId)).data.isAdmin == true
}
match /users/{uid} {
// Can read own data, admin can read all
allow read:
if request.auth.uid == uid
|| isAdmin(request.auth.uid)
// Can set own user data, except the admin flag
allow write:
if request.auth.uid == uid
&& (!('isAdmin' in request.resource.data)
|| request.resource.data.isAdmin == resource.data.isAdmin)
}
match /comments/{comment} {
function isAuthor(userId) {
return userId == get(/databases/$(database)/documents/comments/$(comment)).data.userId;
}
function isAuthorOrAdmin(userId) {
return isAuthor(userId) || isAdmin(userId)
}
allow read
allow create: if request.auth.uid != null
allow update: if isAuthorOrAdmin(request.auth.uid)
allow delete: if isAuthorOrAdmin(request.auth.uid)
}
match /{document=**} {
allow read, write: if false
}
match /locations/{document=**} {
allow read
}
match /videos/{document=**} {
allow read
allow write: if isAdmin(request.auth.uid)
}
}
}