-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirestore.rules
More file actions
43 lines (37 loc) · 1.66 KB
/
Copy pathfirestore.rules
File metadata and controls
43 lines (37 loc) · 1.66 KB
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
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
function isSignedIn() {
return request.auth != null;
}
function isAdmin() {
return isSignedIn() &&
request.auth.token.email == 'Stanislavskii.yo@gmail.com' &&
request.auth.token.email_verified == true;
}
function incoming() { return request.resource.data; }
function existing() { return resource.data; }
function isValidCase(data) {
return data.keys().hasAll(['categoryId', 'imageUrl', 'titleEn', 'titleRu', 'descriptionEn', 'descriptionRu', 'prompt', 'altText', 'createdAt'])
&& data.categoryId is string && data.categoryId.size() <= 128
&& data.imageUrl is string && data.imageUrl.size() <= 2048
&& data.titleEn is string && data.titleEn.size() <= 256
&& data.titleRu is string && data.titleRu.size() <= 256
&& data.descriptionEn is string && data.descriptionEn.size() <= 2048
&& data.descriptionRu is string && data.descriptionRu.size() <= 2048
&& data.prompt is string && data.prompt.size() <= 4096
&& data.altText is string && data.altText.size() <= 1024
&& (data.get('thumbnailUrl', '') is string)
&& (data.get('mediaType', 'image') in ['image', 'video']);
}
match /cases/{caseId} {
allow read: if true;
allow create: if isAdmin() && isValidCase(incoming()) && incoming().createdAt == request.time;
allow update: if isAdmin() && isValidCase(incoming()) && incoming().createdAt == existing().createdAt;
allow delete: if isAdmin();
}
}
}