-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
74 lines (65 loc) · 2.48 KB
/
firestore.rules
File metadata and controls
74 lines (65 loc) · 2.48 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Helper functions
function isSignedIn() {
return request.auth != null;
}
function isOwner(userId) {
return isSignedIn() && request.auth.uid == userId;
}
// Users collection
match /users/{userId} {
allow read: if true;
allow create: if isOwner(userId);
allow update: if isOwner(userId);
allow delete: if isOwner(userId);
}
// Communities collection
match /communities/{communityId} {
allow read: if true;
allow create: if isSignedIn();
allow update: if isSignedIn() && (
resource.data.creatorId == request.auth.uid ||
exists(/databases/$(database)/documents/communityMembers/$(request.auth.uid + '_' + communityId)) &&
get(/databases/$(database)/documents/communityMembers/$(request.auth.uid + '_' + communityId)).data.role in ['admin', 'moderator']
);
allow delete: if isSignedIn() && resource.data.creatorId == request.auth.uid;
}
// Community members
match /communityMembers/{memberId} {
allow read: if true;
allow create: if isSignedIn();
allow update: if isSignedIn();
allow delete: if isSignedIn() && resource.data.userId == request.auth.uid;
}
// Posts collection
match /posts/{postId} {
allow read: if true;
allow create: if isSignedIn();
allow update: if isSignedIn() && (
resource.data.authorId == request.auth.uid ||
exists(/databases/$(database)/documents/communityMembers/$(request.auth.uid + '_' + resource.data.communityId)) &&
get(/databases/$(database)/documents/communityMembers/$(request.auth.uid + '_' + resource.data.communityId)).data.role in ['admin', 'moderator']
);
allow delete: if isSignedIn() && resource.data.authorId == request.auth.uid;
}
// Comments collection
match /comments/{commentId} {
allow read: if true;
allow create: if isSignedIn();
allow update: if isSignedIn() && resource.data.authorId == request.auth.uid;
allow delete: if isSignedIn() && resource.data.authorId == request.auth.uid;
}
// Post votes
match /postVotes/{voteId} {
allow read: if true;
allow write: if isSignedIn() && voteId.matches(request.auth.uid + '_.*');
}
// Comment votes
match /commentVotes/{voteId} {
allow read: if true;
allow write: if isSignedIn() && voteId.matches(request.auth.uid + '_.*');
}
}
}