-
Notifications
You must be signed in to change notification settings - Fork 0
/
firestore.rules
56 lines (47 loc) · 1.55 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// ------------------------- HELPERS -------------------------
function onlyHasAttrs(obj, attrs) {
return obj.keys().hasOnly(attrs);
}
function incoming() {
return request.resource.data;
}
// -------------------------- RULES --------------------------
match /{document=**} {
allow read, write: if false;
}
match /users/{userId}/{document=**} {
allow read: if request.auth.uid == userId;
match /training-blocks/{trainingBlockId} {
function isCorrectSchema() {
return onlyHasAttrs(
request.resource.data,
[
'name',
'exerciseDays',
'archivedAt',
'startedAt',
'exerciseDaysOrdering',
'exercisesCollapsedIncludingIndex'
]
);
}
allow write: if isCorrectSchema();
}
match /exercise-types/{exerciseTypeId} {
function isCorrectSchema() {
return onlyHasAttrs(request.resource.data, ['name', 'unit', 'notes', 'trainingBlockId', 'exercises', 'archivedAt'])
&& incoming().name is string
&& incoming().unit is string
&& incoming().notes is string
&& incoming().trainingBlockId is string
&& incoming().exercises is list
&& incoming().archivedAt is number || incoming().archivedAt == null;
}
allow write: if isCorrectSchema();
}
}
}
}