-
Notifications
You must be signed in to change notification settings - Fork 28
/
firestore.rules
159 lines (140 loc) · 7.34 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /keyboards/v1/definitions/{definitionID} {
allow read;
}
match /keyboards/v2/definitions/{definitionID} {
allow read: if isIndividualAuthor(request.auth.uid, resource)
|| (resource.data.status == 'approved')
|| isOrganizationAuthor(request.auth.uid, resource);
allow create: if isAuthor(request.auth.uid, request.resource)
&& (request.resource.data.status in ['draft', 'in_review']);
allow delete: if isAuthor(request.auth.uid, resource);
allow update: if (
isAuthor(request.auth.uid, resource)
&& (
(request.resource.data.status in ['draft', 'rejected', 'in_review'])
|| (
(resource.data.status == 'approved')
&& (request.resource.data.diff(resource.data).affectedKeys().hasOnly(
["json", "updated_at", "features", "thumbnail_image_url",
"image_url", "description", "stores", "website_url",
"additional_descriptions", "sub_images", "name",
"firmwares", "total_firmware_download_count"])
)
)
)
) || (
(resource.data.status == 'approved')
&& (request.resource.data.diff(resource.data).affectedKeys().hasOnly(
["total_firmware_download_count", "total_firmware_flash_count"])
)
);
match /secure/github {
allow read: if isAuthenticated()
&& (request.auth.uid == getDefinition(definitionID).data.author_uid);
allow create, delete: if isAuthenticated()
&& (request.auth.uid == getDefinition(definitionID).data.author_uid);
}
function getOrganization(organizationID) {
return get(/databases/$(database)/documents/organizations/v1/profiles/$(organizationID));
}
function isIndividualAuthor(requestAuthUid, resourceDefinition) {
return
(isUndefined(resourceDefinition.data, 'author_type') || resourceDefinition.data.author_type == 'individual')
&&
(requestAuthUid == resourceDefinition.data.author_uid);
}
function isOrganizationAuthor(requestAuthUid, resourceDefinition) {
return
(resourceDefinition.data.author_type == 'organization')
&&
(requestAuthUid in getOrganization(resourceDefinition.data.organization_id).data.members);
}
function isAuthor(requestAuthUid, resourceDefinition) {
return
isIndividualAuthor(requestAuthUid, resourceDefinition)
||
isOrganizationAuthor(requestAuthUid, resourceDefinition);
}
}
match /configurations/{configuration} {
allow read;
}
match /keymaps/v1/saved-keymaps/{keymapId} {
allow create: if (request.auth.uid == request.resource.data.author_uid);
allow read: if (request.auth.uid == resource.data.author_uid)
|| (resource.data.status == 'shared');
allow update: if (request.auth.uid == resource.data.author_uid)
&& (request.resource.data.diff(resource.data).affectedKeys().hasOnly(["title", "desc", "updated_at", "status", "author_display_name"]));
allow delete: if (request.auth.uid == resource.data.author_uid);
}
match /keymaps/v1/applied-keymaps/{keymapId} {
allow create: if (request.auth.uid == request.resource.data.applied_uid);
allow read: if (request.auth.uid == resource.data.applied_uid);
allow update: if (request.auth.uid == resource.data.applied_uid);
allow delete: if (request.auth.uid == resource.data.applied_uid);
}
match /organizations/v1/profiles/{organizationId} {
allow create: if false;
allow delete: if false;
allow update: if isAuthenticated()
&& (request.auth.uid in resource.data.members)
&& (request.resource.data.diff(resource.data).affectedKeys().hasOnly(["name", "icon_image_url", "contact_email_address", "members", "updated_at"]));
allow read;
}
match /build/v1/firmwares/{definitionId}/keyboardFiles/{keyboardFileId} {
allow create: if isAuthenticated()
&& (request.auth.uid == getDefinition(definitionId).data.author_uid);
allow update: if isAuthenticated()
&& (request.auth.uid == getDefinition(definitionId).data.author_uid);
allow delete: if isAuthenticated()
&& (request.auth.uid == getDefinition(definitionId).data.author_uid);
allow read;
}
match /build/v1/firmwares/{definitionId}/keymapFiles/{keyboardFileId} {
allow create: if isAuthenticated()
&& (request.auth.uid == getDefinition(definitionId).data.author_uid);
allow update: if isAuthenticated()
&& (request.auth.uid == getDefinition(definitionId).data.author_uid);
allow delete: if isAuthenticated()
&& (request.auth.uid == getDefinition(definitionId).data.author_uid);
allow read;
}
match /build/v1/firmwares/{definitionId} {
allow create: if isAuthenticated()
&& (request.auth.uid == request.resource.data.uid)
&& (request.auth.uid == getDefinition(definitionId).data.author_uid);
allow update: if isAuthenticated()
&& (request.auth.uid == resource.data.uid)
&& (request.auth.uid == getDefinition(definitionId).data.author_uid);
allow read;
}
match /build/v1/tasks/{taskId} {
allow create: if isAuthenticated()
&& (request.auth.uid == request.resource.data.uid);
allow update: if isAuthenticated()
&& (request.auth.uid == resource.data.uid);
allow delete: if isAuthenticated()
&& (request.auth.uid == resource.data.uid);
allow read: if isAuthenticated()
&& (request.auth.uid == resource.data.uid);
}
match /logs/v1/operations/{operationLogID} {
allow create;
allow update: if false;
allow delete: if false;
allow read: if false;
}
function isAuthenticated() {
return request.auth.uid != null;
}
function isUndefined(data, field) {
return !data.keys().hasAll([field]);
}
function getDefinition(definitionID) {
return get(/databases/$(database)/documents/keyboards/v2/definitions/$(definitionID));
}
}
}