-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirestore.rules
62 lines (51 loc) · 2.43 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function authorizedPlaylist(playlistId) {
return request.auth.uid != null
&& request.auth.uid == get(/databases/$(database)/documents/filteredPlaylists/$(playlistId)).data.createdBy;
}
match /filteredPlaylists/{playlistId} {
// Check if user created the current filtered playlist
function isOgUser(compareTo) {
return request.auth.uid != null
&& request.auth.uid == compareTo;
}
allow create: if request.resource.data.keys().hasOnly(['createdBy', 'originId'])
&& request.resource.data.originId != null
&& isOgUser(request.resource.data.createdBy);
allow update: if (
request.resource.data.keys().hasOnly(['createdBy', 'originId'])
// May have `createdAt` property if Firebase Function already triggered. If so, it should not have been modified.
|| (
request.resource.data.keys().hasOnly(['createdBy', 'originId', 'createdAt'])
&& request.resource.data.createdAt == resource.data.createdAt
)
)
&& request.resource.data.originId != null
&& isOgUser(request.resource.data.createdBy)
&& isOgUser(resource.data.createdBy);
allow read, delete: if isOgUser(resource.data.createdBy);
match /filteredSongs/{songId} {
allow create, update: if request.resource.data.keys().hasOnly(['updatedBy', 'markedCriteria'])
&& request.auth.uid == request.resource.data.updatedBy
&& authorizedPlaylist(playlistId);
allow read, delete: if authorizedPlaylist(playlistId);
}
}
match /filterCriteria/{criteriaId} {
allow create: if request.resource.data.keys().hasOnly(['playlistId', 'order', 'purpose', 'description'])
&& authorizedPlaylist(request.resource.data.playlistId);
allow update: if request.resource.data.keys().hasOnly(['playlistId', 'order', 'purpose', 'description'])
&& authorizedPlaylist(resource.data.playlistId);
allow read, delete: if authorizedPlaylist(resource.data.playlistId);
}
match /filterActions/{actionId} {
allow create: if request.resource.data.keys().hasOnly(['playlistId', 'order', 'ifType', 'ifId', 'thenType', 'thenId'])
&& authorizedPlaylist(request.resource.data.playlistId);
allow update: if request.resource.data.keys().hasOnly(['playlistId', 'order', 'ifType', 'ifId', 'thenType', 'thenId'])
&& authorizedPlaylist(resource.data.playlistId);
allow read, delete: if authorizedPlaylist(resource.data.playlistId);
}
}
}