-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
61 lines (51 loc) · 1.65 KB
/
Copy pathfirestore.rules
File metadata and controls
61 lines (51 loc) · 1.65 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
rules_version = '2';
service cloud.firestore {
function isAdmin(db) {
return request.auth != null
&& exists(/databases/$(db)/documents/admins/$(request.auth.uid));
}
function isManager(db) {
return isAdmin(db)
&& get(/databases/$(db)/documents/admins/$(request.auth.uid)).data.role == 'manager';
}
match /databases/{db}/documents {
match /leads/{leadId} {
allow read: if isAdmin(db);
allow create, delete: if false;
allow update: if isAdmin(db)
&& request.resource.data.diff(resource.data).affectedKeys()
.hasOnly(['status', 'assignedTo', 'updatedAt']);
match /notes/{noteId} {
allow read: if isAdmin(db);
allow create: if isAdmin(db)
&& request.resource.data.keys().hasAll(['authorUid', 'text', 'createdAt'])
&& request.resource.data.authorUid == request.auth.uid;
allow update, delete: if false;
}
}
match /partialLeads/{partialLeadId} {
allow read: if isAdmin(db);
allow create, update, delete: if false;
}
match /lostSessions/{lostSessionId} {
allow read: if isAdmin(db);
allow create, update, delete: if false;
}
match /chatSessions/{sessionId} {
allow read, write: if false;
}
match /admins/{uid} {
allow read: if isAdmin(db);
allow create: if isManager(db)
&& request.resource.data.keys().hasAll(['email', 'displayName', 'role']);
allow update, delete: if isManager(db);
}
match /rateLimits/{sessionId} {
allow read, write: if false;
}
match /auditLogs/{logId} {
allow read: if isManager(db);
allow write: if false;
}
}
}