forked from AlexZhidkov/ProjectMarket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirestore.rules
40 lines (39 loc) · 1.26 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /businesses/{document=**} {
allow read: if request.auth.uid != null;
allow write: if request.auth.uid == resource.data.createdBy.uid || isAdmin();
}
match /events/{document=**} {
allow read: if isAdmin();
allow write: if request.auth.uid != null;
}
match /projects/{document=**} {
allow read, write: if isAdmin() || isReferrer();
}
match /students/{userId}/{document=**} {
allow read: if request.auth.uid == userId || isAdmin() || isReferrer() || isBusiness();
allow write: if request.auth.uid == userId || isAdmin();
}
match /users/{userId}/{document=**} {
allow read: if request.auth.uid == userId || isAdmin();
allow write: if request.auth.uid == userId
}
function getUserData(){
return get(/databases/$(database)/documents/users/$(request.auth.uid)).data;
}
function isAdmin(){
return getUserData().role == 'admin';
}
function isReferrer(){
return getUserData().role == 'referrer';
}
function isStudent(){
return getUserData().role == 'student';
}
function isBusiness(){
return getUserData().role == 'business';
}
}
}