Repository navigation
Expand file tree
/
Copy pathfirestore.rules
More file actions
54 lines (49 loc) · 2.24 KB
/
Copy pathfirestore.rules
File metadata and controls
54 lines (49 loc) · 2.24 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Users can read and write their own user document
match /users/{userId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
// Teachers can read students assigned to them
allow read: if request.auth != null &&
request.auth.token.role == 'teacher' &&
get(/databases/$(database)/documents/users/$(userId)).data.teacherId == request.auth.uid;
}
// Users can read their own class data
match /classes/{classId} {
allow read: if request.auth != null &&
get(/databases/$(database)/documents/users/$(request.auth.uid)).data.classId == classId;
}
// Practice sessions can be read by the student who owns them or their teacher
match /practiceSessions/{sessionId} {
allow read, create: if request.auth != null &&
request.auth.uid == resource.data.studentId;
allow update: if request.auth != null &&
request.auth.uid == resource.data.studentId;
// Teachers can read practice sessions of their students
allow read: if request.auth != null &&
request.auth.token.role == 'teacher' &&
get(/databases/$(database)/documents/users/$(resource.data.studentId)).data.teacherId == request.auth.uid;
}
// Diagnostic attempts can be read by the student who owns them or their teacher
match /diagnosticAttempts/{attemptId} {
allow read, create: if request.auth != null &&
request.auth.uid == resource.data.userId;
allow update: if request.auth != null &&
request.auth.uid == resource.data.userId;
// Teachers can read diagnostic attempts of their students
allow read: if request.auth != null &&
request.auth.token.role == 'teacher' &&
get(/databases/$(database)/documents/users/$(resource.data.userId)).data.teacherId == request.auth.uid;
}
// Questions can be read by authenticated users
match /questions/{questionId} {
allow read: if request.auth != null;
}
// Teacher alerts can be read by the teacher they belong to
match /teacherAlerts/{alertId} {
allow read: if request.auth != null &&
request.auth.uid == resource.data.teacherId;
}
}
}