-
Notifications
You must be signed in to change notification settings - Fork 0
/
permissions.bolt
70 lines (61 loc) · 1.5 KB
/
permissions.bolt
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// permissions.bolt
//
// Design goals:
//
// - All logged in user can get a list of users
// - Only admin can create
// - Only admin or currentUser can update or delete
//
// - Only admin can write roles
//
// - Any logged in user can get a list of projects
// - Any logged in user can create a project
// - Only admin can update a project
// - No one can delete a project
//
// See https://www.firebase.com/docs/security/guide/user-security.html
path /users {
read() {
isSignedIn()
}
/{uid} {
/profile {
create() {
isAdmin()
}
update() {
isAdmin() || isCurrentUser(uid)
}
delete() {
isAdmin() || isCurrentUser(uid)
}
}
/roles {
write() { isAdmin() }
}
}
}
path /projects {
read() { isSignedIn() }
/{project_id} {
read() { isSignedIn() }
create() { isSignedIn() }
update() { isAdmin() || isProjectAdmin(project_id) }
delete() { false }
/members {
write() { isAdmin() }
}
/modules {
write() { isAdmin() }
}
}
}
//
// Helper Functions
//
isCurrentUser(id) { auth != null && auth.uid == id }
isSignedIn() { auth != null }
isAdmin() { auth != null && root.users[auth.uid].roles.admin == true }
adminCanUpdate() { auth != null && root.projects[project_id].members[auth.uid].isAdmin == true }
isProjectAdmin(project_id) { auth != null && root.projects[project_id].members[auth.uid].isAdmin == true }
isProjectMember(project_id) { root.projects[project_id].members[auth.uid].exists() }