-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathfirestore.rules
68 lines (56 loc) · 1.82 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
59
60
61
62
63
64
65
66
67
68
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// deny all by default, aka: locked mode
match /{document=**} {
allow read, write: if false;
}
function isSignedIn() {
return request.auth != null;
}
function isOwner(userId) {
return request.auth.uid == userId;
}
function queryLimit(limit) {
return request.query.limit <= limit;
}
function getAdmins() {
return get(/databases/$(database)/documents/admin/allowed-users).data.admins;
}
function isAdmin(email) {
return email in getAdmins();
}
function getAllowedToSignUpUsers() {
return get(/databases/$(database)/documents/admin/allowed-users).data.emails;
}
function isUserAllowedToSignUp(email) {
return email in getAllowedToSignUpUsers();
}
function isConsentAccepted() {
return request.resource.data.consentAccepted == true;
}
match /admin/allowed-users {
allow read, write: if isSignedIn() && isAdmin(request.auth.token.email);
}
match /colors/{colorId} {
allow read: if isSignedIn() && queryLimit(40);
allow create: if isSignedIn() && isAdmin(request.auth.token.email);
}
match /users/{userId} {
allow create: if isUserAllowedToSignUp(request.auth.token.email) && isConsentAccepted();
allow get, update: if isOwner(userId);
match /projects/{projectId} {
allow read: if queryLimit(20) && isOwner(userId);
allow write: if isOwner(userId);
}
match /labels/{labelId} {
allow read: if queryLimit(20) && isOwner(userId);
allow write: if isOwner(userId);
}
match /todos/{todoId} {
allow read: if queryLimit(40) && isOwner(userId);
allow write: if isOwner(userId);
}
}
}
}