-
Notifications
You must be signed in to change notification settings - Fork 2
/
firestore.rules
26 lines (25 loc) · 893 Bytes
/
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
rules_version = '2';
service cloud.firestore {
function isEmpty(resource) {
return resource == null || !("data" in resource);
}
function isOwner(resource) {
return ("owner" in resource.data) && request.auth.uid == resource.data.owner;
}
function isSignedIn() {
return request.auth != null;
}
function isPublic(resource) {
return !("public" in resource.data) || resource.data.public == true;
}
match /databases/{database}/documents {
match /calendars/{calendar} {
allow read, update, delete: if isEmpty(resource) || isPublic(resource) || (isSignedIn() && isOwner(resource));
allow create;
}
match /users/{user} {
allow read, update, delete: if isEmpty(resource) || isEmpty(get(resource.data.calendar)) || isPublic(get(resource.data.calendar)) || (isSignedIn() && isOwner(get(resource.data.calendar)));
allow create;
}
}
}