-
Notifications
You must be signed in to change notification settings - Fork 1
/
firestore.rules
58 lines (55 loc) · 2.78 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
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId}/blogs/{blogId} {
function isUndefined(resource, field) {
return !resource.keys().hasAny([field])
}
allow read: if request.auth.uid == userId;
allow delete: if request.auth.uid == userId;
allow create, update: if request.auth.uid == userId
&& request.resource.data.keys().hasOnly(["title", "url", "feedURL", "feedType", "timestamp", "services", "sendReport"])
&& request.resource.data.title is string
&& request.resource.data.url is string
&& request.resource.data.feedURL is string
&& request.resource.data.feedType is string
&& request.resource.data.timestamp is timestamp
&& request.resource.data.sendReport is bool
&& request.resource.data.services is map
&& request.resource.data.services.keys().hasOnly(["twitter", "countjsoon", "facebook", "hatenabookmark", "hatenastar", "pocket"])
&& request.resource.data.services.twitter is bool
&& request.resource.data.services.countjsoon is bool
&& request.resource.data.services.facebook is bool
&& request.resource.data.services.hatenabookmark is bool
&& request.resource.data.services.hatenastar is bool
&& request.resource.data.services.pocket is bool;
match /items/{itemId} {
function checkCountFields(resource, countType) {
return isUndefined(resource, countType)
|| (resource[countType] is map
&& resource[countType].hasOnly(["count", "timestamp"])
&& resource[countType].count is number
&& resource[countType].timestamp is timestamp);
}
function checkCountMap(resource, field) {
return isUndefined(resource, field)
|| (resource[field] is map
&& checkCountFields(resource[field], "countjsoon")
&& checkCountFields(resource[field], "facebook")
&& checkCountFields(resource[field], "hatenabookmark")
&& checkCountFields(resource[field], "hatenastar")
&& checkCountFields(resource[field], "pocket"));
}
allow read: if request.auth.uid == userId;
allow delete: if request.auth.uid == userId;
allow create, update: if request.auth.uid == userId
&& request.resource.data.keys().hasAll(["title", "url", "published"])
&& request.resource.data.title is string
&& request.resource.data.url is string
&& request.resource.data.published is timestamp
&& checkCountMap(request.resource.data, "count")
&& checkCountMap(request.resource.data, "prevCount")
&& checkCountMap(request.resource.data, "yesterdayCount");
}
}
}
}