-
Notifications
You must be signed in to change notification settings - Fork 52
/
firestore.rules
52 lines (42 loc) · 1.31 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
service cloud.firestore {
match /databases/{database}/documents {
match /companies/{companyId} {
allow read: if isSignedIn() && userBelongsToCompany();
allow update, delete: if companyAdmin()
}
match /teams/{teamId} {
allow read: if isSignedIn() && adminOrEmployee();
allow create: if userAndAdmin();
allow update, delete: if companyAdmin()
}
match /employees/{employeeId} {
allow read: if isSignedIn() && userBelongsToCompany();
allow create: if userAndAdmin();
allow update, delete: if companyAdmin()
}
}
function isSignedIn() {
return (request.auth.uid != null)
}
function userIsAdmin() {
return request.auth.token.role == 'admin'
}
function userBelongsToCompany() {
return request.auth.token.companyId == resource.data.companyId
}
function userAndAdmin() {
return isSignedIn() && userIsAdmin()
}
function companyAdmin() {
return userAndAdmin() && userBelongsToCompany()
}
function adminOrEmployee() {
return userBelongsToCompany() && (userIsAdmin() || resource.data.id == request.auth.uid)
}
function adminOrOwner() {
return userBelongsToCompany() && (userIsAdmin() || resource.data.employeeId == request.auth.uid)
}
function notCreator() {
return resource.data.status != 'creator'
}
}