-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
56 lines (55 loc) · 2.48 KB
/
firestore.rules
File metadata and controls
56 lines (55 loc) · 2.48 KB
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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// setup functions to make consistent
// is the request from the user requesting the
function isRequestingUser(userId) {
return request.auth.uid == userId;
}
// is the user admin
function isAdmin() {
return get(/databases/$(database)/documents/users/$(request.auth.uid)).data.isAdmin == true;
}
// is the user a reader of the data
function isReader() {
return get(/databases/$(database)/documents/users/$(request.auth.uid)).data.isReader == true;
}
// helper to check if they are updating something important
function notUpdating(field) {
return !(field in request.resource.data) || (resource.data[field] && resource.data[field] == request.resource.data[field])
}
// there is no invalid change if not changing the private things here
function noInvalidDataChange() {
return (!('isAdmin' in request.resource.data) || false == request.resource.data['isAdmin'])
&& (!('isReader' in request.resource.data) || false == request.resource.data['isReader']);
// && notUpdating('forbiddenData');
}
// Allow public read access to user data, but only content owners can write
match /users/{userId}/{documents=**} {
allow read, delete: if isRequestingUser(userId) || isAdmin();
// Disallow the creation of users with active subscriptions / admin rights
allow update : if (noInvalidDataChange() && isRequestingUser(userId)) || isAdmin();
allow create: if noInvalidDataChange() && isRequestingUser(userId);
}
// Allow public read access to user data, but only admins can create and edit
match /item_categories/{categoryId}/{documents=**} {
allow create, write, delete, update : if isAdmin();
allow read : if isReader();
}
// Allow public read access to user data, but only admins can create and edit
match /items/{categoryId}/{documents=**} {
allow create, write, delete, update : if isAdmin();
allow read : if isReader();
}
// Allow public read access to user data, but only admins can create and edit
match /quantities/{categoryId}/{documents=**} {
allow create, write, delete, update : if isAdmin();
allow read : if isReader();
}
// Allow public write access to track activity, but only admins can read
match /activity/{documents=**} {
allow create : if isReader();
allow read, delete, update : if isAdmin();
}
}
}