-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
107 lines (90 loc) · 3.4 KB
/
Copy pathfirestore.rules
File metadata and controls
107 lines (90 loc) · 3.4 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isSignedIn() {
return request.auth != null;
}
function isOwner(uid) {
return request.auth.uid == uid;
}
function companyDoc(companyId) {
return get(/databases/$(database)/documents/companies/$(companyId));
}
function isCompanyMember(companyId) {
return request.auth.uid in companyDoc(companyId).data.members;
}
function isCompanyMemberLocal() {
return request.auth.uid in resource.data.members;
}
function isCompanyAdmin(companyId) {
return request.auth.uid in companyDoc(companyId).data.admins;
}
function envDoc(companyId, envId) {
return get(/databases/$(database)/documents/companies/$(companyId)/environments/$(envId));
}
function isEnvMember(companyId, envId) {
return request.auth.uid in envDoc(companyId, envId).data.members;
}
function isEnvMemberLocal() {
return request.auth.uid in resource.data.members;
}
function isEnvAdmin(companyId, envId) {
return request.auth.uid in envDoc(companyId, envId).data.admins;
}
match /users/{uid} {
allow get: if isSignedIn() && isOwner(uid);
allow list: if false;
allow create: if isSignedIn() && isOwner(uid);
allow update: if isSignedIn() && (
isOwner(uid) ||
request.resource.data.diff(resource.data).affectedKeys().hasOnly(['companyIds', 'updatedAt'])
);
allow delete: if false;
match /private/{docId} {
allow read, write: if isSignedIn() && isOwner(uid);
}
match /companies/{companyId} {
allow read, write: if isSignedIn() && (
isOwner(uid) ||
isCompanyMember(companyId)
);
}
}
match /companies/{companyId} {
allow read: if isSignedIn() && isCompanyMemberLocal();
allow create: if isSignedIn()
&& request.auth.uid == request.resource.data.ownerId
&& request.auth.uid in request.resource.data.members;
allow update: if isSignedIn() && isCompanyMember(companyId)
&& (
request.resource.data.get('deletedAt', null) == resource.data.get('deletedAt', null)
|| request.auth.uid == resource.data.ownerId
);
allow delete: if false;
match /environments/{envId} {
allow read: if isSignedIn() && isEnvMemberLocal();
allow create: if isSignedIn()
&& request.auth.uid in request.resource.data.members
&& request.auth.uid in request.resource.data.admins;
allow update: if isSignedIn() && isEnvMember(companyId, envId)
&& (
request.resource.data.get('deletedAt', null) == resource.data.get('deletedAt', null)
|| isEnvAdmin(companyId, envId)
);
allow delete: if false;
match /inventory/{itemId} {
allow read: if isSignedIn() && isEnvMember(companyId, envId);
allow create: if isSignedIn() && isEnvMember(companyId, envId);
allow update: if isSignedIn() && isEnvMember(companyId, envId);
allow delete: if false;
}
match /sales/{saleId} {
allow read: if isSignedIn() && isEnvMember(companyId, envId);
allow create: if isSignedIn() && isEnvMember(companyId, envId);
allow update: if isSignedIn() && isEnvMember(companyId, envId);
allow delete: if false;
}
}
}
}
}