-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
60 lines (50 loc) · 1.88 KB
/
firestore.rules
File metadata and controls
60 lines (50 loc) · 1.88 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isAdmin() {
return request.auth != null && get(/databases/$(database)/documents/users/$(request.auth.uid)).data.isAdmin == true;
}
function isAuthed() {
return request.auth != null;
}
// `draft_state`: Everyone can read. Only admins can write.
match /draft_state/{document=**} {
allow read: if true;
allow write: if isAdmin();
}
// `teams`: Everyone can read. Only backend or admins can write.
match /teams/{teamNumber} {
allow read: if true;
allow write: if isAdmin();
}
// `users`: Everyone can read basic ranking info.
// Users can update their own document but CANNOT modify protected fields.
// Draft submissions go through the submitDraft Cloud Function (uses admin SDK).
match /users/{userId} {
allow read: if true;
allow create: if isAuthed()
&& request.auth.uid == userId
&& request.resource.data.isAdmin == false
&& (!request.resource.data.keys().hasAny(['score']) || request.resource.data.score == 0)
&& (!request.resource.data.keys().hasAny(['rank']) || request.resource.data.rank == 0)
&& !request.resource.data.keys().hasAny(['seasons']);
allow update: if (request.auth.uid == userId
&& !request.resource.data.diff(resource.data).affectedKeys().hasAny(['isAdmin', 'rank', 'score', 'seasons', 'teams', 'h2h']))
|| isAdmin();
allow delete: if isAdmin();
}
// H2H weeks: everyone can read, only backend/admin writes
match /h2h_weeks/{weekId} {
allow read: if true;
allow write: if isAdmin();
match /picks/{userId} {
allow read: if true;
allow write: if false;
}
match /results/{matchupId} {
allow read: if true;
allow write: if false;
}
}
}
}