-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
35 lines (31 loc) · 1.12 KB
/
Copy pathfirestore.rules
File metadata and controls
35 lines (31 loc) · 1.12 KB
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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isAuthed() { return request.auth != null; }
function myRole() { return get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role; }
function isTeacher() { return isAuthed() && myRole() == 'teacher'; }
match /users/{uid} {
allow read: if isAuthed();
allow create: if request.auth.uid == uid;
allow update: if request.auth.uid == uid
&& (!("role" in resource.data) || resource.data.role == null || request.resource.data.role == resource.data.role);
allow delete: if false;
}
match /materials/{fileId} {
allow read: if isAuthed();
allow create, update, delete: if false;
}
match /forum_posts/{postId} {
allow read: if isAuthed();
allow create, update, delete: if false;
match /replies/{replyId} {
allow read: if isAuthed();
allow create, update, delete: if false;
}
}
match /analytics_events/{eventId} {
allow read: if isTeacher();
allow create, update, delete: if false;
}
}
}