-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfirestore.rules
More file actions
110 lines (89 loc) · 3.83 KB
/
firestore.rules
File metadata and controls
110 lines (89 loc) · 3.83 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
108
109
110
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isSignedIn() {
return request.auth != null;
}
//Check owner of new doc (request.resource.data.owner)
// function isOwnerWrite() {
// return debug(request.auth.uid == request.resource.data.owner);
// }
//
// //Check owner of existing doc (resource.data.owner)
// function isOwnerRead() {
// return debug(request.auth.uid == resource.data.owner);
// }
//
// function signedInAndIsOwner() {
// return debug(request.auth != null) && debug(request.auth.uid == resource.data.owner);
// }
// For now disable all writes in the database if not admin
allow write: if false;
match /user/{id} {
allow read: if isSignedIn() && id == request.auth.uid
}
match /network/{document=**} {
allow read: if true;
}
match /team/{teamId} {
function belongsToTeam() {
let userId = request.auth.uid;
return exists(/databases/$(database)/documents/team/$(teamId)/teamMember/$(userId));
}
function signedInAndBelongsToTeam() {
return isSignedIn() && belongsToTeam();
}
function isTeamOwner() {
let teamOwner = get(/databases/$(database)/documents/team/$(teamId)).data.owner;
let userId = request.auth.uid;
return teamOwner == userId;
}
// FIXME signedInAndBelongsToTeam is causing issues on what seems to be a list call;
// allow read: if signedInAndBelongsToTeam();
allow read: if isSignedIn();
// allow write: if isSignedIn() && request.resource.data.owner === request.auth.uid;
match /teamMember/{id} {
allow read: if isTeamOwner() || request.auth.uid == resource.data.userId;
}
match /teamNetwork/{id} {
allow read: if isSignedIn();
}
}
// For group queries
match /{teamPath=**}/teamMember/{id} {
// function isTeamOwner() {
// let teamOwner = get(/databases/$(database)/documents/$(teamPath)).data.owner;
// let userId = request.auth.uid;
//
// return teamOwner == userId;
// }
// allow read: if isTeamOwner() || request.auth.uid == resource.data.userId ;
allow read: if request.auth.uid == resource.data.userId ;
}
match /project/{projectId} {
function belongsToProject() {
let userId = request.auth.uid;
let projectTeamId = get(/databases/$(database)/documents/project/$(projectId)).data.teamId;
return exists(/databases/$(database)/documents/team/$(projectTeamId)/teamMember/$(userId));
}
function signedInAndBelongsToProject() {
return isSignedIn() && belongsToProject();
}
// Rules on the project document itself
allow read: if isSignedIn();
// allow write: if belongsToProject();
match /{subCollection}/{subDocument=**} {
allow read: if signedInAndBelongsToProject();
}
match /projectUser/{id} {
allow read: if resource.data.userId == request.auth.uid || signedInAndBelongsToProject();
}
match /projectUserWalletDfns/{id} {
allow read: if resource.data.userId == request.auth.uid || signedInAndBelongsToProject();
}
match /projectUserWalletSafe/{id} {
allow read: if resource.data.userId == request.auth.uid || signedInAndBelongsToProject();
}
}
}
}