-
Notifications
You must be signed in to change notification settings - Fork 0
/
firestore.rules
42 lines (34 loc) · 1.25 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{user} {
allow read: if true;
allow write: if false;
}
match /boards/{board} {
function userOwnsBoard() {
let isAuthed = request.auth != null;
let isOwner = request.auth.uid == get(/databases/$(database)/documents/boards/$(board)).data.owner;
return isAuthed && isOwner;
}
function userIsEditor() {
let isAuthed = request.auth != null;
let isEditor = exists(/databases/$(database)/documents/boards/$(board)/permissions/$(request.auth.uid)) && get(/databases/$(database)/documents/boards/$(board)/permissions/$(request.auth.uid)).data.role == 'editor';
return isAuthed && isEditor;
}
function hasPerms() {
return userOwnsBoard() || userIsEditor()
}
allow create: if request.auth != null && request.auth.uid == request.resource.data.owner;
allow read: if request.auth != null;
allow update, delete: if hasPerms();
match /categories/{category} {
allow read: if request.auth != null;
allow write: if hasPerms();
}
match /questions/{question} {
allow read, write: if hasPerms();
}
}
}
}