-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirestore.rules
44 lines (34 loc) · 1.87 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// TODO: assign users from admin app an admin role
// true if the admin is not anonymous
function registeredAdmin() {
return get(/databases/$(database)/documents/admins/$(request.auth.uid)).data.isAnonymous == false;
}
// true if the admin is signed in anonymously and has free experiments left
function guestWithFreeExperiments() {
return get(/databases/$(database)/documents/admins/$(request.auth.uid)).data.isAnonymous == true && get(/databases/$(database)/documents/admins/$(request.auth.uid)).data.experimentCount < get(/databases/$(database)/documents/settings/generalSettings).data.freeExperimentCount;
}
// only everyone to read the general settings, don't allow any writes
match /settings/generalSettings {
allow read: if request.auth != null;
}
// only allow admin to access their own admin document
match /admins/{adminId} {
allow read, write: if request.auth != null && adminId == request.auth.uid;
}
match /experiments/{experimentDocId} {
// allow admin to create a new experiment either if they are registered (unlimited) or if they have a free experiment left
allow create: if registeredAdmin() || guestWithFreeExperiments();
// allow only an admin to update or delete an experiment that they created themselves
allow update, delete: if request.auth != null && request.auth.uid == resource.data.adminUid;
// allow all signed in users and admins to read experiments
allow read: if request.auth != null;
//
match /users/{userId} {
allow read, write: if true; //request.auth != null && resource.parent.data.adminUid == request.auth.uid; //get(/databases/$(database)/documents/experiments/$(experimentDocId)).data.adminUid == request.auth.uid;
}
}
}
}