-
Notifications
You must be signed in to change notification settings - Fork 0
/
firestore.rules
27 lines (23 loc) · 971 Bytes
/
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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function getRoles() {
return getRolesFor(request.auth.uid);
}
function getRolesFor(userId) {
return get(/databases/$(database)/documents/users/$(userId)).data.roles;
}
function hasAnyRoles() {
let roles = getRoles();
return roles.student || roles.teacher || roles.admin;
}
match /users/{user} {
allow read: if (request.auth.uid == resource.id) || hasAnyRoles();
allow write: if (request.auth.uid == resource.id && request.resource.data.roles == resource.data.roles) || getRoles().admin;
}
match /passes/{pass} {
allow read, update: if request.auth.uid == resource.data.issuer || request.auth.uid == resource.data.holder || getRoles().admin;
allow create: if getRoles().student && request.resource.data.holder == request.auth.uid && getRolesFor(request.resource.data.issuer).teacher;
}
}
}