-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfirestore.rules
43 lines (43 loc) · 1.63 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isAuthenticated() {
return request.auth != null
}
match /stats/{stat} {
allow read: if isAuthenticated();
}
match /questions/{stat} {
allow read: if isAuthenticated();
}
match /exams/{exam} {
allow read: if isAuthenticated();
match /questions/{question} {
allow read: if isAuthenticated();
}
}
match /schools/{school} {
allow read: if isAuthenticated();
}
match /courses/{course} {
allow read: if isAuthenticated();
}
match /reports/{report} {
allow create: if isAuthenticated() &&
request.resource.data.keys().hasAll(['uid', 'exam', 'createdAt', 'history', 'score', 'numQuestions', 'percentage', 'grade']) &&
request.resource.data.keys().hasOnly(['uid', 'exam', 'createdAt', 'history', 'score', 'numQuestions', 'percentage', 'grade']) &&
request.resource.data.uid == request.auth.uid &&
request.resource.data.grade != null &&
request.resource.data.grade in ['A', 'B', 'C', 'D', 'E', 'F'] &&
request.resource.data.percentage is number &&
request.resource.data.percentage >= 0 &&
request.resource.data.percentage <= 100 &&
request.resource.data.score is number &&
request.resource.data.score >= 0 &&
request.resource.data.numQuestions is number &&
request.resource.data.numQuestions >= 0 &&
request.resource.data.numQuestions >= request.resource.data.score &&
request.resource.data.numQuestions == request.resource.data.history.size();
}
}
}