-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.rules.bolt
More file actions
163 lines (137 loc) · 3.53 KB
/
database.rules.bolt
File metadata and controls
163 lines (137 loc) · 3.53 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Super-User: isAdmin
isAdmin() {
auth != null && root["admin"][auth.uid]
}
// Validate a uid against the currently logged in user
isCurrentUser(uid) {
auth != null && auth.uid == uid
}
// get conference for id
// hardcoded path: /conference/$confid
confById(confid) {
root["conference"][confid]
}
// get secrets for conference id
// hardcoded path: /secret/$confid
confSecret(confid) {
root["secret"][confid]
}
// has the user a secret for conference
// hardcoded path: /profile/$userid/secret/$confid
userHasSecret(confid) {
auth != null &&
root["profile"][auth.uid] != null &&
root["profile"][auth.uid].secret != null &&
root["profile"][auth.uid].secret[confid] != null
}
// get the user a secret for conference
// hardcoded path: /profile/$userid/secret/$confid
userSecret(confid) {
root["profile"][auth.uid].secret[confid]
}
// Check if current user has a role in a conference
// hardcoded path: /secret/$confid/$role/$usersecret
hasRole(confid, role) {
auth != null &&
userHasSecret(confid) &&
confSecret(confid) != null &&
confSecret(confid)[role] != null &&
confSecret(confid)[role][userSecret(confid)] != null
}
// Check if current user is a reviewer
isReviewer(confid) {
hasRole(confid, "reviewer")
}
// Check for a currently open conference
isConfOpen(confid) {
confById(confid).cfpFrom < now && confById(confid).cfpTo > now
}
// Simple email validation - not bullet proof
type Email extends String {
validate() { this.matches(/[\w+-]+@([\w-]+\.)+[\w-]+/i) }
}
type Profile {
bio: String | Null,
firstName: String | Null,
displayName: String | Null,
email: Email | Null,
comment: String | Null,
secret: String[]
}
type Conference {
name: String,
description: String,
cfpFrom: Number,
cfpTo: Number,
dateFrom: Number | Null,
dateTo: Number | Null,
topics: String | Null,
logo: String | Null,
url: String | Null,
instructionsUrl: String | Null,
where: String | Null,
durations: String[],
write() { isAdmin() }
read() { true }
}
type Proposal {
speaker: String,
title: String,
abstract: String,
duration: Number | Null,
comment: String | Null,
}
path /admin is Boolean[] {
write() { isAdmin() }
read() { isAdmin() }
}
path /conference {
read() { true }
}
path /secret {
write() { isAdmin() }
read() { isAdmin() }
}
path /profiles {
read() { true }
write() { true }
}
path /conference/{conf} is Conference;
path /profile {
read() { isAdmin() }
write() { isAdmin() }
}
path /profile/{uid} is Profile {
read() { isCurrentUser(uid) }
write() { isCurrentUser(uid) }
}
// Admin can read and write all proposals
// for any conference
path /proposal {
read() { isAdmin() }
write() { isAdmin() }
}
// a reviewer can always read and list the proposals of a conf
path /proposal/{conf} {
read() { isReviewer(conf) }
}
// a user can always read and list their proposals
// a user can change, add or delete their proposals as long as open
path /proposal/{conf}/{uid} {
read() { isCurrentUser(uid) }
write() { isConfOpen(conf) && isCurrentUser(uid) }
}
// During opening time everyone can create
// During opening time only the author can change
// Only the author or a reviewer can read
path /proposal/{conf}/{uid}/{id} is Proposal;
// a reviewer can see and update their reviews
path /review/{conf}/{uid} {
read() { isAdmin() || (isReviewer(conf) && isCurrentUser(uid)) }
write() { isAdmin() || (isReviewer(conf) && isCurrentUser(uid)) }
}
// admin can see and create speaker reviews
path /speaker-review {
read() { isAdmin() }
write() { isAdmin() }
}