This repository was archived by the owner on Mar 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirestore.rules
79 lines (60 loc) · 2.52 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
75
76
77
78
79
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// "get" and "list" fall under the "read" category
// "create", "delete", and "update" fall under the "write" category
function isAuthenticated() {
return request.auth.uid != null
}
function isAuthor() {
return request.auth.uid == resource.data.authorID
}
function isHexColorValid(color) {
return color is string && color.matches('#([a-fA-F0-9]{3}){1,2}')
}
function isNotEmpty(value) {
return value is string && value.size() > 0
}
function isTimestampValid(ts) {
return ts is timestamp
}
function isVisibilityValid(visibility) {
return visibility is string && visibility in ['public', 'private']
}
match /groups/{groupID} {
function isCreateGroupValid() {
return isNotEmpty(request.resource.data.author) &&
isNotEmpty(request.resource.data.authorID) &&
isHexColorValid(request.resource.data.color) &&
request.resource.data.markers is list &&
isNotEmpty(request.resource.data.name) &&
isTimestampValid(request.resource.data.tsCreated) &&
request.auth.uid == request.resource.data.authorID
}
allow read: if isAuthenticated() && isAuthor()
allow create: if isAuthenticated() && isCreateGroupValid()
allow update: if isAuthenticated() && isAuthor() && isCreateGroupValid() && isTimestampValid(request.resource.data.tsUpdated)
allow delete: if isAuthenticated() && isAuthor()
}
match /markers/{markerID} {
function isCreateMarkerValid() {
return isNotEmpty(request.resource.data.author) &&
isNotEmpty(request.resource.data.authorID) &&
request.resource.data.images is list &&
request.resource.data.latLng != null &&
isNotEmpty(request.resource.data.name) &&
isTimestampValid(request.resource.data.tsCreated) &&
isVisibilityValid(request.resource.data.visibility)
}
allow read: if isAuthenticated() && (isAuthor() || resource.data.visibility == 'public')
allow create: if isAuthenticated() && isCreateMarkerValid()
allow update: if isAuthenticated() && isCreateMarkerValid() && isTimestampValid(request.resource.data.tsUpdated)
allow delete: if isAuthenticated() && isAuthor()
}
match /usernames/{username} {
allow get: if true
allow create: if isAuthenticated()
allow update, delete: if isAuthenticated() && isAuthor()
}
}
}