Repository navigation
Expand file tree
/
Copy pathfirestore.rules
More file actions
174 lines (161 loc) · 6.3 KB
/
Copy pathfirestore.rules
File metadata and controls
174 lines (161 loc) · 6.3 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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
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'])
}
function doesNotChangeNextDigestAt() {
// Only admins/automatic processes should be able to change the
// email digest notification times
return !request.resource.data.diff(resource.data).affectedKeys().hasAny(['nextDigestAt'])
}
function doesNotChangePhoneVerified() {
// Only the completePhoneVerification cloud function (Admin SDK) sets phoneVerified
return !request.resource.data.diff(resource.data).affectedKeys().hasAny(['phoneVerified'])
}
// 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() && doesNotChangeNextDigestAt() && doesNotChangePhoneVerified()
}
// 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"
}
// Admin-managed news collection used by the admin UI and public news page
match /news/{nid} {
allow read: if true;
allow write: if request.auth.token.get("role", "user") == "admin";
}
// Emails sent to legislators, written by functions only. A reader can
// read the records of their own letters.
match /legislatorMail/{id} {
allow read: if request.auth != null && resource.data.uid == request.auth.uid;
}
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"
}
}
// Roll call votes, written only by the scrapeHouseRollCalls /
// scrapeSenateRollCalls functions (Admin SDK). Public, read-only.
match /votes/{rollCallId} {
allow read: if true;
allow write: if false;
}
// Per-member votes; recursive match so collection-group queries
// (e.g. all votes for one memberCode) are allowed from the client.
match /{path=**}/vote/{memberCode} {
allow read: if true;
allow write: if false;
}
match /ballotQuestions/{id} {
allow read: if true;
allow write: if false;
}
match /lobbyingRegistrants/{id} {
allow read: if true;
allow write: if false;
}
match /lobbyingFilings/{id} {
allow read: if true;
allow write: if false;
}
match /lobbyingMeta/{id} {
allow read: if true;
allow write: if false;
// billSummaries_{court} docs store per-bill counts as small docs in
// this subcollection (not as a single JSON blob) to avoid Firestore's
// 1MB per-document/field size limit as a session's filings accumulate.
match /bills/{billId} {
allow read: if true;
allow write: if false;
}
// clientSummaries/firmSummaries store one small doc per client/firm
// (same reasoning as billSummaries above) so the clients and firms
// browse pages can read a precomputed rollup instead of scanning the
// full, capped-at-2000 lobbyingRegistrants query client-side.
match /clients/{clientId} {
allow read: if true;
allow write: if false;
}
match /firms/{firmId} {
allow read: if true;
allow write: if false;
}
}
match /transcriptions/{tid} {
// public, read-only
allow read: if true
allow write: if false
// public, read-only
match /utterances/{uid} {
allow read: if true
allow write: if false
}
// public, read-only
match /paragraphs/{pid} {
allow read: if true
allow write: if false
}
}
}
}