-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
67 lines (57 loc) · 2.05 KB
/
Copy pathfirestore.rules
File metadata and controls
67 lines (57 loc) · 2.05 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// User Helper Functions
function isSignedIn() {
return request.auth != null;
}
function isAdmin() {
return isSignedIn() && (
get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role == 'admin' ||
get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role == 'chiefAdmin'
);
}
function isChiefAdmin() {
return isSignedIn() && get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role == 'chiefAdmin';
}
// Users Collection
match /users/{userId} {
allow read: if isSignedIn();
allow create: if isChiefAdmin();
allow update: if isSignedIn() && (
// Only Chief Admin can update roles or status
(isChiefAdmin()) ||
// Regular users can only update their own profile (excluding sensitive fields)
(request.auth.uid == userId &&
!request.resource.data.diff(resource.data).affectedKeys().hasAny(['role', 'status', 'isVerified', 'isActive']))
);
allow delete: if isChiefAdmin();
}
// Notifications Collection (Broadcasts)
match /notifications/{notificationId} {
allow read: if isSignedIn();
allow create: if isAdmin();
allow update, delete: if false; // Immutable audit log
}
// Notification Logs
match /notification_logs/{logId} {
allow read: if isAdmin();
allow write: if false; // System only (Cloud Functions)
}
// Incident Chats Collection
match /incident_chats/{incidentId} {
allow read: if isSignedIn();
allow create: if isAdmin();
allow update: if isSignedIn();
match /messages/{messageId} {
allow read: if isSignedIn();
allow create: if isAdmin() || (isSignedIn() && exists(/databases/$(database)/documents/incident_chats/$(incidentId)));
allow update, delete: if false;
}
}
// Default deny
match /{document=**} {
allow read, write: if false;
}
}
}