-
Notifications
You must be signed in to change notification settings - Fork 1
/
firestore.rules
59 lines (47 loc) · 1.36 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
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read: if hasAccess() || isSelf();
allow update: if hasAccess() ||
// Only able to change own displayName
(isSelf() && (request.writeFields.size() == 1) && ('displayName' in request.writeFields));
allow create, delete: if isAdmin();
function isSelf() {
return request.auth.uid == userId;
}
}
match /projects/{projectId} {
allow read: if hasAccess() || userCanAccess();
allow update: if hasAccess();
allow create, delete: if isAdmin();
function userCanAccess() {
return getProjectData().users[request.auth.uid] == true
}
function getProjectData() {
return get(/databases/$(database)/documents/projects/$(projectId)).data
}
match /{projectDetailCollections=**} {
allow read: if hasAccess() || userCanAccess();
allow update, create, delete: if hasAccess();
}
}
function isSignedIn() {
return request.auth != null;
}
function getUserData() {
return get(/databases/$(database)/documents/users/$(request.auth.uid)).data
}
function access(role) {
return getUserData()['access'] == role;
}
function isAdmin() {
return access('admin') || access('master');
}
function isAuthor() {
return access('author');
}
function hasAccess() {
return isAdmin() || isAuthor();
}
}
}