-
Notifications
You must be signed in to change notification settings - Fork 0
/
firestore.rules
49 lines (49 loc) · 1.86 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userID} {
allow read: if request.auth != null;
allow create: if request.auth != null && request.auth.uid == request.resource.data.id;
allow update: if request.auth != null && request.auth.uid == resource.data.id;
}
match /books/{bookID} {
function bookData() {
return get(/databases/$(database)/documents/books/$(bookID)).data;
}
function readPermission () {
return request.auth != null;
}
function createPermission () {
return request.auth != null;
}
function updatePermission () {
return request.auth != null &&
request.auth.uid == resource.data.created_by &&
request.auth.uid == request.resource.data.created_by;
}
function createLinePermission (data) {
return request.auth != null && request.auth.uid in data.members;
}
allow read: if readPermission();
allow create: if createPermission();
allow update, delete: if updatePermission();
match /lines/{lineID} {
allow read: if readPermission();
allow create: if createLinePermission(bookData());
allow update, delete: if updatePermission();
}
}
match /book_users/{book_usersID} {
function bookUsersData() {
return get(/databases/$(database)/documents/book_users/$(book_usersID)).data;
}
function updatePermission (data) {
return (request.auth != null && request.auth.uid in data.members) ||
request.resource.data.users[request.auth.uid].role == 'reader'; //debil, reforzar
}
allow read: if request.auth != null;
allow create: if request.auth != null && request.auth.uid == request.resource.data.created_by;
allow update: if updatePermission(bookUsersData());
}
}
}