-
Notifications
You must be signed in to change notification settings - Fork 39
/
firestore.rules
49 lines (39 loc) · 1.16 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
service cloud.firestore {
match /databases/{database}/documents {
match /tanam-types/{typeId} {
allow read: if hasAnyRole();
allow write: if isAtLeastAdmin();
}
match /tanam-users/{uid} {
allow read: if isSignedInAs(uid);
// Delete and create must be done manually
allow update: if isSignedInAs(uid) && request.resource.data.role == resource.data.role;
}
match /tanam-documents/{documentId} {
allow read: if hasAnyRole();
allow write: if isPublisher();
match /revisions/{revisionId} {
allow read: if hasAnyRole();
allow write: if false;
}
}
function hasUserRole(role) {
return isSignedIn() && role == request.auth.token.tanamRole;
}
function hasAnyRole() {
return isSignedIn() && request.auth.token.tanamRole != null;
}
function isAtLeastAdmin() {
return hasUserRole("admin");
}
function isPublisher() {
return isAtLeastAdmin() || hasUserRole("publisher");
}
function isSignedIn() {
return request.auth != null;
}
function isSignedInAs(uid) {
return isSignedIn() && request.auth.uid == uid;
}
}
}