-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfirestore.rules
38 lines (31 loc) · 1.12 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /apps/{appName} {
function readWriteAccess() {
return get(/databases/$(database)/documents/apps/digital-paper-edit/users/$(request.auth.uid)).data.access == "READWRITE";
}
function isAdmin() {
return get(/databases/$(database)/documents/apps/digital-paper-edit/users/$(request.auth.uid)).data.role == "ADMIN";
}
match /users/{document=**} {
allow read, write: if isAdmin()
}
match /users/{userId}/{document=**} {
allow read, write: if readWriteAccess() || request.auth.uid == userId;
}
match /projects/{document=**} {
allow read, write
}
function isOnProject(pId) {
return request.auth.uid in get(/databases/$(database)/documents/apps/digital-paper-edit/projects/$(pId)).data.users;
}
match /projects/{pId} {
allow read, write: if isOnProject(pId) || isAdmin();
}
match /projects/{pId}/{document=**} {
allow read, write: if isOnProject(pId) || isAdmin();
}
}
}
}