-
Notifications
You must be signed in to change notification settings - Fork 0
/
firestore.rules
88 lines (73 loc) · 2.87 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
match /user-data/{userId} {
allow get, list;
allow create, update: if request.resource.id == request.auth.uid;
}
match /boards-info/{boardId} {
allow get, list;
allow create: if request.auth.uid != null &&
request.auth.uid == request.resource.data.owner &&
request.auth.uid in request.resource.data.admins &&
request.auth.uid in request.resource.data.members;
allow update: if ((
request.resource.data.public == resource.data.public &&
request.resource.data.members == resource.data.members
) ||
request.auth.uid in resource.data.admins
) && (
request.resource.data.admins == resource.data.admins ||
request.auth.uid == resource.data.owner
) && request.auth.uid in resource.data.members && (
request.resource.data.owner == resource.data.owner || (
request.auth.uid == resource.data.owner &&
request.resource.data.owner in request.resource.data.admins
)
);
match /join-requests/{requestId} {
allow create: if request.auth.uid != null &&
requestId == request.auth.uid &&
!(request.auth.uid in get(/databases/$(database)/documents/boards-info/$(boardId)).data.members);
allow get: if request.auth.uid != null && (
request.auth.uid in get(/databases/$(database)/documents/boards-info/$(boardId)).data.admins ||
request.auth.uid == requestId
);
allow list, delete: if request.auth.uid != null &&
request.auth.uid in get(/databases/$(database)/documents/boards-info/$(boardId)).data.admins;
}
}
match /boards/{boardId} {
function getBoardInfo () {
return get(/databases/$(database)/documents/boards-info/$(boardId)).data;
}
function userIsMember () {
let boardInfo = getBoardInfo();
return (request.auth.uid != null && request.auth.uid in boardInfo.members);
}
function userCanViewBoard () {
return userIsMember() || getBoardInfo().public;
}
match /events/{eventId} {
allow get, list: if userCanViewBoard();
allow create, update: if userIsMember();
}
match /subjects/{subjectId} {
allow get, list: if userCanViewBoard();
allow create, update: if userIsMember();
}
match /activity/{activityId} {
allow get, list: if userCanViewBoard();
allow create: if userIsMember() &&
request.resource.data.type in ['event-create', 'event-edit', 'event-archive', 'event-restore'] &&
request.resource.data.user == request.auth.uid;
}
match /user-data/{userId} {
allow get, create, update: if userId == request.auth.uid;
}
}
}
}