-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfirestore.rules
208 lines (176 loc) · 6.33 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// firestore
service cloud.firestore {
// databases
match /databases/{database}/documents {
// users
match /users/{userId} {
allow read: if isDocumentOwner(userId);
allow create: if isAuthenticated();
allow update: if isDocumentOwner(userId) && (isAdmin() || !('isAdmin' in request.resource.data));
allow delete: if isAdmin();
// certifications
match /certifications/{certificationId} {
allow read;
allow create: if isAuthenticated();
allow update: if isDocumentOwner(userId);
allow delete: if isDocumentOwner(userId);
}
// educations
match /educations/{educationId} {
allow read;
allow create: if isAuthenticated();
allow update: if isDocumentOwner(userId);
allow delete: if isDocumentOwner(userId);
}
// workhistorys
match /workhistorys/{workhistoryId} {
allow read;
allow create: if isAuthenticated();
allow update: if isDocumentOwner(userId);
allow delete: if isDocumentOwner(userId);
}
}
// reviews
match /reviews/{reviewId} {
allow read;
allow create: if isDocumentOwner(request.resource.data.reviewerId);
allow update: if isDocumentOwner(resource.data.reviewerId);
allow delete: if isAdmin();
}
// portfolio work
match /portfolio/{userId}/work/{w} {
allow read;
allow create: if isDocumentOwner(userId);
allow update: if isDocumentOwner(userId);
allow delete: if isDocumentOwner(userId);
}
// transactions
match /transactions/{transactionId} {
allow read;
allow create: if isAuthenticated();
allow update: if userIsSender();
allow delete: if isAdmin();
}
// who
match /who/{userId}/user/{who} {
allow read: if isDocumentOwner(who);
allow create: if isAuthenticated() && request.auth.uid == request.resource.data.address;
allow update: if isDocumentOwner(who) && request.auth.uid == request.resource.data.address;
allow delete: if isAdmin();
}
// viewed-users
match /viewed-users/{userId}/viewed/{document=**} {
allow read;
allow create: if isDocumentOwner(userId);
allow update: if isDocumentOwner(userId);
allow delete: if isAdmin();
}
// notifications
match /notifications/{userId} {
allow read;
allow create: if isAuthenticated();
allow update: if isAuthenticated();
allow delete: if isAuthenticated();
}
// skill-tags
match /skill-tags/{skill} {
allow read;
}
// chats
match /chats/{userId} {
allow read: if isDocumentOwner(userId)
// channels
match /channels/{channelId} {
allow read: if isCommonChannel(channelId) || isDocumentOwner(userId);
allow create: if isCommonChannel(channelId);
allow update: if isCommonChannel(channelId);
allow delete: if isAdmin();
// messages
match /messages/{messageId} {
allow read: if isCommonChannel(channelId);
allow create: if isCommonChannel(channelId);
allow update: if isCommonChannel(channelId);
allow delete: if isAdmin();
}
}
}
// features
match /features/{document=**} {
allow read;
}
// limepay-payments
match /limepay-payments/{jobId} {
allow read;
allow create: if isAuthenticated();
allow update: if userIsClientOrProvider();
allow delete: if isAdmin();
}
// jobs
match /jobs/{jobId} {
allow read: if isDocumentOwner(resource.data.clientId) || isDocumentOwner(resource.data.providerId);
allow create: if request.auth.uid == request.resource.data.clientId;
allow update: if userIsClientOrProvider();
allow delete: if isAdmin();
}
// public-jobs
match /public-jobs/{jobId} {
allow read: if resource.data.visibility == 'public'
|| isDocumentOwner(resource.data.clientId)
|| (resource.data.visibility == 'invite' && isInvitedUser(resource.data));
allow create: if isAuthenticated();
allow update: if isDocumentOwner(resource.data.clientId);
allow delete: if isAdmin();
// bids
match /bids/{bidId} {
allow read;
allow create: if canCreateBid(getPublicJob(jobId));
allow update: if isDocumentOwner(bidId);
allow delete: if isAdmin();
}
}
// shoppers
match /shoppers/{userId} {
allow read;
allow create: if isDocumentOwner(userId);
allow update: if isDocumentOwner(userId);
allow delete: if isAdmin();
}
// --------------------------------------------------------------------------------
// functions
function isAuthenticated() {
return request.auth != null
}
function isDocumentOwner(userId) {
return request.auth.uid == userId
|| isAdmin()
}
function userIsSender() {
return request.resource.data.senderId == request.auth.uid
|| isAdmin()
}
function userIsClientOrProvider() {
return request.resource.data.clientId == request.auth.uid
|| request.resource.data.providerId == request.auth.uid
|| isAdmin()
}
function getUserData() {
return get(/databases/$(database)/documents/users/$(request.auth.uid)).data
}
function isAdmin() {
return getUserData().isAdmin
}
function isCommonChannel(channelId) {
return request.auth.uid in channelId.split('-')
}
function isInvitedUser(job) {
return request.auth.uid in job.invites
}
function getPublicJob(jobId) {
return get(/databases/$(database)/documents/public-jobs/$(jobId)).data
}
function canCreateBid(job) {
return job.visibility == 'public' || (job.visibility == 'invite' && isInvitedUser(job))
}
// --------------------------------------------------------------------------------
}
}