-
Notifications
You must be signed in to change notification settings - Fork 1
/
storage.rules
81 lines (68 loc) · 2.84 KB
/
storage.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
// Firebase Storage Rules
rules_version = '2';
service firebase.storage {
function userIsAuthenticated() {
return request.auth.uid != null;
}
function currentUser() {
return request.auth.uid;
}
function userIsJAC() {
return request.auth.token.email.matches('(.*@judicialappointments|.*@justice)[.](digital|gov[.]uk)');
//return request.auth.token.email_verified
//&& request.auth.token.email.matches('.*@judicialappointments[.](digital|gov[.]uk)')
}
function isOkForDownload() {
return
resource.metadata == null ||
!('status' in resource.metadata) ||
('status' in resource.metadata && resource.metadata.status != 'infected');
}
function isOkForUpload() {
return
(request.resource == null) ||
(
request.resource.size > 0
&& request.resource.size <= 2 * 1024 * 1024
&& request.resource.name.matches('.*\\.(pdf|docx|doc|odt|txt|fodt|xlsx)')
);
}
function screenshotIsOkForUpload() {
return
(request.resource == null) ||
(
request.resource.size > 0
&& request.resource.size <= 2 * 1024 * 1024 * 5
&& request.resource.name.matches('.*\\.(png)')
);
}
match /b/{bucket}/o {
match /exercise/{exerciseId}/{fileName} {
allow read: if isOkForDownload();
allow write: if userIsAuthenticated() && userIsJAC() && isOkForUpload();
}
match /exercise/{exerciseId}/user/{userId}/{fileName} {
allow read: if userIsAuthenticated() && userIsJAC() && isOkForDownload();
allow read: if userIsAuthenticated() && currentUser() == userId && isOkForDownload();
allow write: if userIsAuthenticated() && currentUser() == userId && isOkForUpload();
allow write: if userIsAuthenticated() && userIsJAC() && isOkForUpload();
}
match /exercise/{exerciseId}/application/{applicationId}/assessor/{userId}/{fileName} {
allow read: if userIsAuthenticated() && userIsJAC() && isOkForDownload();
allow read: if userIsAuthenticated() && currentUser() == userId && isOkForDownload();
allow write: if userIsAuthenticated() && currentUser() == userId && isOkForUpload();
}
match /exercise/{exerciseId}/application/{applicationId}/assessor/jac/{fileName} {
allow read: if userIsAuthenticated() && userIsJAC() && isOkForDownload();
allow write: if userIsAuthenticated() && userIsJAC() && isOkForUpload();
}
match /exercise/{exerciseId}/application/{applicationId}/jac/{fileName} {
allow read: if userIsAuthenticated() && userIsJAC() && isOkForDownload();
allow write: if userIsAuthenticated() && userIsJAC() && isOkForUpload();
}
match /bugReport/{bugReportId}/{fileName} {
allow read: if userIsAuthenticated() && userIsJAC() && isOkForDownload();
allow write: if userIsAuthenticated() && userIsJAC() && screenshotIsOkForUpload();
}
}
}