-
Notifications
You must be signed in to change notification settings - Fork 0
/
firestore.rules
61 lines (53 loc) · 1.84 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
50
51
52
53
54
55
56
57
58
59
60
61
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow list: if false;
}
function getOwnerID(roomID) {
let owner = get(/databases/$(database)/documents/rooms/$(roomID)/Owner/Owner);
return owner == null ? null : owner.data.uid;
}
match /rooms/{roomID} {
function checkData() {
return request.auth != null &&
request.resource.data.size() == 2 &&
request.resource.data.Classes is map &&
request.resource.data.StudentsReady is list;
}
allow create: if roomID.matches("^(\\d){6,}#[a-zA-Z0-9]{64,}$") &&
checkData();
allow update: if checkData();
allow delete: if request.auth != null &&
request.auth.uid == getOwnerID(roomID);
}
match /rooms/{roomID}/Classroom/{classID} {
function checkData() {
return request.resource.data.size() == 3 &&
request.resource.data.StudentsReady is list &&
request.resource.data.StudentsTaken is list &&
request.resource.data.currentTeacher is string;
}
allow update, create: if checkData();
}
match /rooms/{roomID}/Examiner/{examinerName} {
function checkData() {
return request.resource.data.size() == 3 &&
request.resource.data.Classroom is string &&
request.resource.data.Student is map &&
request.resource.data.isResting is bool;
}
allow update, create: if checkData();
}
match /rooms/{roomID}/Owner/{ownerID} {
allow read: if request.auth != null &&
request.auth.uid == getOwnerID(roomID);
allow create: if getOwnerID(roomID) == null;
allow update: if false;
}
match /{document=**} {
allow write: if false;
allow read;
}
}
}