-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfirestore.rules
68 lines (54 loc) · 2.33 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
63
64
65
66
67
68
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /comments/{commentId} {
allow read;
allow create:
if request.resource.data.keys().hasOnly(['comment', 'createdAt', 'postId', 'userId', 'username'])
&& request.resource.data.comment.size() <= 500
&& request.resource.data.createdAt == request.time
&& exists(/databases/$(database)/documents/posts/$(request.resource.data.postId))
&& request.auth.uid == request.resource.data.userId
&& request.resource.data.username == get(/databases/$(database)/documents/users_2/$(request.auth.uid)).data.username;
allow delete: if request.auth.uid == resource.data.userId;
}
match /feeds/{userId} {
allow get;
}
match /likes/{likeId} {
allow read;
allow create:
if request.resource.id == request.auth.uid + '_' + request.resource.data.postId
&& request.resource.data.keys().hasOnly(['postId', 'userId'])
&& exists(/databases/$(database)/documents/posts/$(request.resource.data.postId))
&& exists(/databases/$(database)/documents/users_2/$(request.resource.data.userId));
allow delete: if request.auth.uid == resource.data.userId;
}
match /notifications/{notificationId} {
allow read: if request.auth.uid == resource.data.userId;
allow update:
if request.auth.uid == resource.data.userId
&& request.resource.data.diff(resource.data).affectedKeys().hasOnly(['read'])
&& request.resource.data.read == true;
}
match /posts/{postId} {
allow read:
if resource.data.published == true
|| request.auth.uid == resource.data.userId;
allow update:
if request.resource.data.diff(resource.data).affectedKeys().hasOnly(['likes', 'updatedAt'])
&& (
!('likes' in resource.data)
|| request.resource.data.likes.diff(resource.data.likes).affectedKeys().hasOnly([request.auth.uid])
)
&& (request.resource.data.likes[request.auth.uid] == true || !(request.auth.uid in request.resource.data.likes))
&& request.resource.data.updatedAt == request.time;
allow delete:
if request.auth.uid == resource.data.userId;
}
match /users_2/{userId} {
allow get;
allow list: if request.query.limit == 1;
}
}
}