-
Notifications
You must be signed in to change notification settings - Fork 0
/
firestore.rules
41 lines (32 loc) · 951 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /articles/{articleID} {
allow read;
allow update: if isAdmin() || verifyInteraction()
allow write: if isAdmin()
}
match /submissions/{submissionID} {
allow read, create;
allow update, delete: if isAdmin()
}
match /tags/{tagID} {
allow read;
}
match /users/{userEmail} {
allow read;
allow create, update: if request.auth.token.email == userEmail;
}
function verifyInteraction() {
let affectedKeys = request.resource.data.diff(resource.data).affectedKeys();
let allowedUpdates = ["likes", "submittedComments"];
return affectedKeys.hasOnly(allowedUpdates);
}
function isAdmin() {
let userEmail = request.auth.token.email;
let userDoc = get(/databases/$(database)/documents/users/$(userEmail));
return request.auth.token.email_verified &&
userDoc.data.isAdmin == true;
}
}
}