-
-
Notifications
You must be signed in to change notification settings - Fork 120
/
firestore.rules
88 lines (80 loc) · 3.28 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Make sure the uid of the requesting user matches name of the user document
// The wildcard {userId} gives us access to that value in a function
match /users/{userId}/{document=**} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
match /events/{id} {
// public, read-only
allow read: if true;
allow write: if false;
}
match /generalCourts/{document=**} {
// public, read-only
allow read: if true;
allow write: if false;
}
match /billTracker/{document=**} {
// public, read-only
allow read: if true;
allow write: if false;
}
match /profiles/{uid} {
function validUser() { // is the user the same as the profile?
return request.auth.uid == uid
}
function doesNotChangeRole() {
return !request.resource.data.diff(resource.data).affectedKeys().hasAny(['role'])
}
// either the change doesn't include the public field,
// or the user is a base user (i.e. not an org)
function validPublicChange() {
return !request.resource.data.diff(resource.data).affectedKeys().hasAny(['public'])
|| request.auth.token.get("role", "user") == "user"
}
// Always visible to the user and public if `public` is true.
allow read: if resource.data.public || request.auth.uid == uid
// Only normal "user" roles & admins can toggle visibility.
allow create: if validUser() && request.resource.data.role == 'user' && request.resource.data.public == false
// Always readable and writable to admins
allow read, write: if request.auth.token.get("role", "user") == "admin"
// Allow users to make updates except to delete their profile or set the role field.
// Only admins can delete a user profile or set the user role field.
allow update: if validUser() && doesNotChangeRole() && validPublicChange()
}
// Allow querying publications individually or with a collection group.
match /{path=**}/publishedTestimony/{id} {
// public, read-only. all for admin
allow read: if true
allow read, write: if request.auth.token.get("role", "user") == "admin"
}
match /reports/{rid} {
// Anyone can report
allow create: if true
// Only admins can do anything with it
allow read, write: if request.auth.token.get("role", "user") == "admin"
}
match /users/{uid} {
allow read, write: if request.auth.token.get("role", "user") == "admin"
match /draftTestimony/{id} {
// private, only accessible by the user
allow read, write: if request.auth.uid == uid
}
match /userNotificationFeed/{id} {
// TODO: do not allow users to modify content, only view status.
// private, only accessible by the user
allow read, write: if request.auth.uid == uid
}
match /users/{uid}/activeTopicSubscriptions/{topicName} {
allow read, write: if debug(request.auth.uid == uid);
}
match /archivedTestimony/{id} {
// Publicly readable, for posterity.
allow read: if true
allow read, write: if request.auth.token.get("role", "user") == "admin"
}
}
}
}