-
Notifications
You must be signed in to change notification settings - Fork 2
/
database.rules.bolt
81 lines (65 loc) · 1.7 KB
/
database.rules.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
71
72
73
74
75
76
77
78
79
80
81
type User {
displayName: String,
email: String,
photoURL: String,
uid: String,
repairs: Boolean[],
isManager: Boolean | Null,
}
type Date extends String {
validate() { this.test(/^\d{8}$/) }
}
type Time extends String {
validate() { this.test(/^[012][0-9]:[0-5][0-9]$/) }
}
type Comment {
message: String,
datetime: Number,
user: String,
}
type Repair {
title: String,
description: String,
date: Date,
time: Time,
completed: Boolean | Null,
approved: Boolean | Null,
user: String | Null,
comments: Comment[] | Null,
}
path /users {
read() { auth != null }
}
path /users/{uid} is User {
validate() { this.uid == uid }
create() { isManager() || isCurrentUser(uid) }
read() { auth != null }
update() { isManager() || isCurrentUser(uid) }
delete() { isManager() && !isCurrentUser(uid) }
}
path /users/{uid}/isManager {
validate() { this == prior(this) || (isManager() && !isCurrentUser(uid)) }
write() { isManager() && !isCurrentUser(uid) }
}
path /users/{uid}/repairs {
write() { false }
}
path /repairs {
read() { isManager() }
write() { isManager() }
}
path /repairs/{id} is Repair {
read() { isManager() || isCurrentUser(this.user) }
}
path /repairs/{id}/comments/{key2} is Comment {
create() { isManager() || isCurrentUser(root.repairs[id].user) }
}
path /repairs/{id}/completed {
read() { isManager() || isCurrentUser(this.parent().user) }
write() { isManager() || (isCurrentUser(this.parent().user) && this == true) }
}
path /repairs/{id}/approved {
validate() { this == false || this.parent().completed == true }
}
isCurrentUser(uid) { auth !== null && auth.uid === uid }
isManager() { auth !== null && prior(root.users[auth.uid].isManager) }