-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfirestore.rules
58 lines (49 loc) · 3.69 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
allow read, write: if false;
match /libraries/{library} {
allow create, delete, list: if false;
allow get;
allow update: if library in request.auth.token.librariesJoined && (library in request.auth.token.permissions.MANAGE_LIBRARY || library in request.auth.token.librariesOwned);
}
match /libraries/{library}/books/{book} {
allow get, list: if library in request.auth.token.librariesJoined;
allow create, update: if library in request.auth.token.librariesJoined && (library in request.auth.token.permissions.MANAGE_BOOKS || library in request.auth.token.librariesOwned);
allow delete: if false;
}
match /{path=**}/copies/{copy} {
allow list: if resource.data.libraryID in request.auth.token.librariesJoined;
}
match /libraries/{library}/books/{book}/copies/{copy} {
allow get: if library in request.auth.token.librariesJoined;
allow create, update, delete: if library in request.auth.token.librariesJoined && (library in request.auth.token.permissions.MANAGE_BOOKS || library in request.auth.token.librariesOwned);
}
match /libraries/{library}/books/{book}/reviews/{review} {
allow read: if library in request.auth.token.librariesJoined;
allow delete: if library in request.auth.token.librariesJoined && (library in request.auth.token.permissions.MANAGE_BOOKS);
}
match /libraries/{library}/checkouts/{checkout} {
allow get: if library in request.auth.token.librariesJoined && (request.auth.uid == resource.data.userID || library in request.auth.token.permissions.MANAGE_CHECKOUTS || library in request.auth.token.librariesOwned);
allow list: if library in request.auth.token.librariesJoined && (library in request.auth.token.permissions.MANAGE_CHECKOUTS || library in request.auth.token.librariesOwned);
allow update: if library in request.auth.token.librariesJoined && (library in request.auth.token.permissions.MANAGE_CHECKOUTS || library in request.auth.token.librariesOwned);
allow create, delete: if false;
}
match /libraries/{library}/users/{user} {
allow get: if request.auth.uid == user || library in request.auth.token.permissions.MANAGE_USERS || library in request.auth.token.librariesOwned;
allow list: if library in request.auth.token.librariesJoined && (resource.data.uid == request.auth.uid || library in request.auth.token.permissions.MANAGE_USERS || library in request.auth.token.permissions.CHECK_OUT || library in request.auth.token.librariesOwned);
allow create, delete: if false;
allow update: if library in request.auth.token.librariesJoined && ((library in request.auth.token.permissions.MANAGE_USERS && user != request.auth.uid) || library in request.auth.token.librariesOwned);
}
match /libraries/{library}/joinRequests/{joinRequest} {
allow create: if request.auth != null;
allow delete, update: if false;
allow get: if joinRequest == request.auth.uid || library in request.auth.token.librariesJoined && (library in request.auth.token.permissions.MANAGE_USERS || library in request.auth.token.librariesOwned);
allow list: if library in request.auth.token.librariesJoined && (library in request.auth.token.permissions.MANAGE_USERS || library in request.auth.token.librariesOwned);
}
match /libraries/{library}/statistics/{statistic} {
allow write, list: if false;
allow get: if library in request.auth.token.librariesJoined && (library in request.auth.token.permissions.MANAGE_LIBRARY || library in request.auth.token.librariesOwned);
}
}
}