-
Notifications
You must be signed in to change notification settings - Fork 0
/
firestore.rules
74 lines (58 loc) · 2.21 KB
/
firestore.rules
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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// CONFIGS
// Config
match /config/config {
// Allow all users to retrieve config
allow read: if request.auth.uid != null
}
match /config/seenMids {
allow update: if request.auth.uid != null
}
// CAMERAS
// Camera information
match /cameras/{targetUid} {
// Allow cameras to read their own info
allow read: if request.auth.uid == targetUid
// Allow owners to read and update their cameras' info (turn off)
allow read, update: if request.auth.uid == resource.data.ownerUid
// Allow cameras to update online status
allow update: if request.auth.uid == targetUid
&& request.resource.data.ownerUid == resource.data.ownerUid // Enforce unchanged
}
// Camera logs
match /cameras/{targetCameraUid}/logs/{log} {
// Allow cameras to create and update their own logs
allow create, update: if request.auth.uid == targetCameraUid
}
// USERS
// User information
match /users/{targetUid} {
// Allow users to read/ write their own information
allow read: if request.auth.uid == targetUid
allow write: if request.auth.uid == targetUid
&& request.resource.data.uid == resource.data.uid // Enforce unchanged
}
function requestIsFromCameraOwnedBy(targetUid){
return targetUid == get(/databases/$(database)/documents/cameras/$(request.auth.uid)).data.ownerUid
}
// A user's events
match /users/{targetUid}/events/{doc} {
// Allow cameras to create/update events to their owner's events collection
allow create, update: if requestIsFromCameraOwnedBy(targetUid)
// Allow users to see their events
allow read, delete: if request.auth.uid == targetUid
}
// System information, stats
match /users/{targetUid}/stats/{day} {
// Allow camers to:
// get: check if a new doc exists
// create: to create a new stats doc
// update: send new stats updates
allow get, create, update: if requestIsFromCameraOwnedBy(targetUid)
// Allow users to see their stats
allow read: if request.auth.uid == targetUid
}
}
}