-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirestore.rules
79 lines (63 loc) · 1.88 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
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
service cloud.firestore {
match /databases/{database}/documents {
match /tanam/{siteId} {
allow read: if hasAnyRole();
allow write: if isAtLeastAdmin();
match /document-types/{typeId} {
allow read: if hasAnyRole();
allow write: if isAtLeastAdmin();
}
match /documents/{documentId} {
allow read: if hasAnyRole();
allow write: if isAtLeastAdmin();
match /revisions/{revisionId} {
allow read: if hasAnyRole();
allow write: if false;
}
}
match /files/{fileId} {
allow read: if hasAnyRole();
allow write: if isPublisher();
}
match /notifications/{notificationId} {
allow read: if isAtLeastAdmin();
allow write: if isAtLeastAdmin();
}
match /themes/{document=**} {
allow read: if hasAnyRole();
allow write: if isAtLeastAdmin();
}
match /users/{document=**} {
allow read, write: if isAtLeastAdmin();
}
match /user-roles/{document=**} {
allow read, write: if isAtLeastAdmin();
}
match /users/{userId} {
allow read: if isSignedInAs(userId);
allow write: if isSignedInAs(userId);
}
function hasUserRole(role) {
return isSignedIn() && role in request.auth.token.tanam[siteId];
}
function hasAnyRole() {
return isSignedIn() && request.auth.token.tanam[siteId].size() > 0;
}
function isSuperAdmin() {
return hasUserRole("superAdmin");
}
function isAtLeastAdmin() {
return isSuperAdmin() || hasUserRole("admin");
}
function isPublisher() {
return isAtLeastAdmin() || hasUserRole("publisher");
}
}
function isSignedIn() {
return request.auth != null;
}
function isSignedInAs(uid) {
return isSignedIn() && request.auth.uid == uid;
}
}
}