-
Notifications
You must be signed in to change notification settings - Fork 1
/
firestore.rules
49 lines (40 loc) · 1.41 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 {
function isSignedIn() {
return request.auth.uid != null;
}
function hasRole(role) {
let roles = {"admin": 1, "writer": 2};
return isSignedIn() && roles[role] == get(/databases/$(database)/documents/sensitive-user-data/$(request.auth.token.email)).data.role;
}
function isDataOwner() {
return resource.data.uID == request.auth.uid;
}
match /blog-entries/{document=**} {
allow read: if resource.data.listed == true || hasRole("writer") || hasRole("admin");
allow write: if hasRole("writer") || hasRole("admin");
}
match /events/{document=**} {
allow read;
allow write: if hasRole("admin");
}
match /collection-metadata/{document=**} {
allow read;
allow write: if hasRole("admin");
}
match /team/{document=**} {
allow read;
allow write: if hasRole("admin");
}
match /users/{document=**} {
allow get, update, delete: if isDataOwner() || hasRole("admin");
allow list: if hasRole("admin");
// Solo puede crear el objeto usuario si el id del usuario en el body corresponde con el id del usuario en el token
allow create: if isSignedIn() && request.resource.data.uID == request.auth.uid;
}
match /sensitive-user-data/{document=**} {
allow read, write: if hasRole("admin");
}
}
}