-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.rules.bolt
102 lines (84 loc) · 1.9 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
type User {
displayName: String,
email: String,
photoURL: String,
uid: String,
billingAddress: String | Null,
shippingAddress: String | Null,
orders: Object | Null,
}
type Role {
isAdmin: Boolean,
isManager: Boolean,
}
type Product {
name: String,
description: String,
image: String,
price: Number,
}
type Cart {
quantities: Number[],
}
type Order extends Cart {
uid: String,
shippingAddress: String,
status: String,
}
path /users {
read() { isAdmin() }
write() { false }
}
path /users/{uid} is User {
create() { isCurrentUser(uid) || isAdmin() }
read() { isCurrentUser(uid) || isAdmin() }
update() { isCurrentUser(uid) || isAdmin() }
delete() { isAdmin() }
}
path /users/{uid}/email {
update() { false }
}
path /users/{uid}/orders/{id} {
update() { false }
}
path /roles {
read() { isAdmin() }
write() { false }
}
path /roles/{uid} is Role {
read() { isAdmin() || isCurrentUser(uid) }
write() { isAdmin() }
}
path /products {
read() { true }
write() { false }
}
path /products/{id} is Product {
create() { isManager() || isAdmin() }
read() { true }
update() { isManager() || isAdmin() }
delete() { isAdmin() }
}
path /cart/{uid} is Cart {
create() { isCurrentUser(uid) }
read() { isCurrentUser(uid) }
update() { isCurrentUser(uid) }
delete() { isCurrentUser(uid) || isAdmin() }
}
path /orders {
read() { isManager() || isAdmin() }
}
path /orders/{id} is Order {
create() { isCurrentUser(this.uid) }
read() { isCurrentUser(this.uid) || isManager() || isAdmin() }
update() { false }
delete() { isAdmin() }
}
path /orders/{id}/status {
create() { isCurrentUser(this.parent().uid) }
update() { isManager() }
delete() { false }
}
isCurrentUser(uid) { auth !== null && auth.uid === uid }
isAdmin() { auth !== null && prior(root.roles[auth.uid].isAdmin) }
isManager() { auth !== null && prior(root.roles[auth.uid].isManager) }