-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirestore.rules
38 lines (31 loc) · 1.14 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function signedIn() {
return request != null && request.auth != null && request.auth.uid != null;
}
function isUser(userId) {
return request.auth.uid == userId;
}
function hasCompany(companyId) {
return companyId == get(/databases/$(database)/documents/users/$(request.auth.uid)).data.companyId;
}
match /decisions/{decisionId} {
allow read: if signedIn() && hasCompany(resource.data.companyId);
allow create: if signedIn()
allow update, delete: if signedIn() && hasCompany(resource.data.companyId);
function decisionData() {
return get(/databases/$(database)/documents/decisions/$(decisionId)).data
}
match /feedback/{feedbackId} {
allow read: if signedIn() && hasCompany(decisionData().companyId);
allow create: if signedIn()
allow update, delete: if signedIn() && hasCompany(decisionData().companyId);
}
}
match /users/{userId} {
allow read: if hasCompany(resource.data.companyId);
allow write: if isUser(userId);
}
}
}