-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
88 lines (78 loc) · 3.29 KB
/
Copy pathfirestore.rules
File metadata and controls
88 lines (78 loc) · 3.29 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Helper functions
function isAuthenticated() {
return request.auth != null;
}
function isOwner(userId) {
return isAuthenticated() && request.auth.uid == userId;
}
function isAdmin() {
return isAuthenticated() &&
get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role == 'admin';
}
// Users collection
match /users/{userId} {
allow read: if isAuthenticated();
allow create: if isAuthenticated() && request.auth.uid == userId;
allow update: if isOwner(userId) || isAdmin();
allow delete: if isAdmin();
}
// Events collection
match /events/{eventId} {
allow read: if true; // Anyone can read events
allow create: if isAuthenticated() &&
request.resource.data.createdBy == request.auth.uid;
allow update: if isAuthenticated() &&
(resource.data.createdBy == request.auth.uid || isAdmin());
allow delete: if isAuthenticated() &&
(resource.data.createdBy == request.auth.uid || isAdmin());
}
// RSVPs collection
match /rsvps/{rsvpId} {
allow read: if isAuthenticated();
allow create: if isAuthenticated() &&
request.resource.data.userId == request.auth.uid;
allow update: if isAuthenticated() &&
resource.data.userId == request.auth.uid;
allow delete: if isAuthenticated() &&
(resource.data.userId == request.auth.uid || isAdmin());
}
// Announcements collection
match /announcements/{announcementId} {
allow read: if true; // Anyone can read published announcements
allow create: if isAuthenticated();
allow update: if isAuthenticated() &&
(resource.data.createdBy == request.auth.uid || isAdmin());
allow delete: if isAuthenticated() &&
(resource.data.createdBy == request.auth.uid || isAdmin());
}
// Comments collection
match /comments/{commentId} {
allow read: if true; // Anyone can read comments
allow create: if isAuthenticated() &&
request.resource.data.userId == request.auth.uid;
allow update: if false; // Comments cannot be edited
allow delete: if isAuthenticated() &&
(resource.data.userId == request.auth.uid || isAdmin());
}
// Reviews collection
match /reviews/{reviewId} {
allow read: if true; // Anyone can read reviews
allow create: if isAuthenticated() &&
request.resource.data.userId == request.auth.uid;
allow update: if false; // Reviews cannot be edited
allow delete: if isAuthenticated() &&
(resource.data.userId == request.auth.uid || isAdmin());
}
// Notifications collection
match /notifications/{notificationId} {
allow read: if isAuthenticated() && resource.data.userId == request.auth.uid;
allow create: if isAuthenticated();
allow update: if isAuthenticated() && resource.data.userId == request.auth.uid;
allow delete: if isAuthenticated() &&
(resource.data.userId == request.auth.uid || isAdmin());
}
}
}