forked from ONEARMY/community-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirestore.rules.WiP
32 lines (30 loc) · 1.44 KB
/
firestore.rules.WiP
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
// WiP - CC - 2020-02-24
// As part of future security update will make better use of firestore rules, as stubbed out below
// Note - will also need to include any legacy revisions as required
service cloud.firestore {
// rules will apply to all docs in database
match /databases/{database}/documents {
// Function to check whether request user has specific permission set in user database
function hasUserRole(username,role){
// TODO - look up a profile to see if the user has specific role (e.g. admin)
// NOTE - this is not currently possible as the username is not sent with a request
// but could be made possible by setting the firebase auth name to the username
// and ensuring all users had a userRoles property
// NOTE 2 - possible code below but would need testing (https://firebase.google.com/docs/reference/rules/rules.List)
// return role in get(/databases/$(database)/documents/v3_users/$(username)).data.userRoles
return true
}
// Function to check if request to modify a document is by the auth owner
function isSameUser(username){
return get(/databases/$(database)/documents/v3_users/$(username)).data._authID==request.auth.uid
}
match /v3_users/{username} {
allow read, write: if hasUserRole('admin')
allow read,write
}
// users can read/write their own user docs
match /v3_users/{username} {
allow read, write: if isSameUser(username)
}
}
}