-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
56 lines (45 loc) · 1.75 KB
/
Copy pathfirestore.rules
File metadata and controls
56 lines (45 loc) · 1.75 KB
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
service cloud.firestore {
match /databases/{database}/documents {
function userExists() {
return (exists(/databases/$(database)/documents/Users/$(request.auth.uid)) == true);
}
function userIsAuthorized() {
return (request.auth.uid in get(/databases/$(database)/documents/Users/authorized).data) &&
(get(/databases/$(database)/documents/Users/authorized).data[request.auth.uid] == true);
}
function userIsAdmin() {
return (request.auth.uid in get(/databases/$(database)/documents/Users/admin).data) &&
(get(/databases/$(database)/documents/Users/admin).data[request.auth.uid] == true);
}
function getContrib(id) {
return get(/databases/$(database)/documents/Contributions/$(id));
}
function userIsOwner(doc) {
return (doc != null && "owner" in doc.data && request.auth.uid == doc.data.owner);
}
match /Contributions/{document=**} {
allow create: if userExists() && userIsAuthorized();
allow read, write: if userExists() && userIsAuthorized() && (userIsAdmin() || userIsOwner(resource));
}
match /Contributions/{contrib}/{sub=**} {
allow create: if userExists() && userIsAuthorized();
allow read, write: if userExists() && userIsAuthorized() && (userIsAdmin() || userIsOwner(getContrib(contrib)));
}
match /Users/admin {
allow read;
allow write: if userExists() && userIsAdmin();
}
match /Users/authorized {
allow read;
allow write: if userExists() && userIsAdmin();
}
match /Users/{uid} {
allow read;
allow create, write: if (userIsAdmin() || request.auth.uid == uid);
}
match /Contributions/published {
allow read;
allow write: if userExists() && userIsAdmin();
}
}
}