-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirestore.rules
33 lines (32 loc) · 1.38 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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /rooms/{room} {
function isValidRoom(){
let hasExactAmountOfProperties = request.resource.data.size() == 2;
let isCorrectVersion = request.resource.data.version == 1;
let hasSameNameAsDocumentId = request.resource.data.name == room;
return hasExactAmountOfProperties && isCorrectVersion && hasSameNameAsDocumentId;
}
allow get: if true;
allow create, update: if isValidRoom();
allow delete, list: if false;
}
match /timers/{timer} {
function isValidTimer(){
let hasExactAmountOfProperties = request.resource.data.size() == 4;
let isCorrectVersion = request.resource.data.version == 1;
let endTimeIsValid = request.resource.data.endTime != null;
let typeIsValid = request.resource.data.type == "Work" || request.resource.data.type == "Break" ;
let durationSecondsIsValid = request.resource.data.durationSeconds > 0;
return hasExactAmountOfProperties && isCorrectVersion && endTimeIsValid && typeIsValid && durationSecondsIsValid;
}
function roomExist(){
return exists(/databases/$(database)/documents/rooms/$(timer)) == true
}
allow read: if true;
allow create, update: if roomExist() && isValidTimer();
allow delete, list: if false;
}
}
}