-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirestore.rules
47 lines (41 loc) · 1.56 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
service cloud.firestore {
function isSubscriber(database, token) {
return (
request.auth != null &&
get(/databases/$(database)/documents/podcasts/$(token)) != null &&
request.auth.uid in get(/databases/$(database)/documents/podcasts/$(token)).data["subscribers"]
);
}
function isPodcastOwner(database, token) {
return (
request.auth != null &&
get(/databases/$(database)/documents/podcasts/$(token)) != null &&
request.auth.uid == get(/databases/$(database)/documents/podcasts/$(token)).data["owner"]
);
}
function isEpisodeOwner(database, token, episode) {
return (
request.auth != null &&
get(/databases/$(database)/documents/podcasts/$(token)/episodes/$(episode)) != null &&
request.auth.uid == get(/databases/$(database)/documents/podcasts/$(token)/episodes/$(episode)).data["owner"]
);
}
function isUser() {
return request.auth != null;
}
match /databases/{database}/documents {
match /podcasts/{token} {
allow create: if isUser();
allow update, delete: if isPodcastOwner(database, token);
allow read: if isSubscriber(database, token);
match /episodes/{episode} {
allow read, create: if isSubscriber(database, token);
allow update, delete: if isEpisodeOwner(database, token, episode);
}
}
match /profiles/{userId} {
allow read: if true;
allow create, update, delete: if request.auth.uid == userId;
}
}
}