forked from google/ground-platform
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstorage.rules
More file actions
95 lines (84 loc) · 2.82 KB
/
Copy pathstorage.rules
File metadata and controls
95 lines (84 loc) · 2.82 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
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
/**
* Copyright 2024 The Ground Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
/**
* Returns true iff the user is signed in.
*/
function isSignedIn() {
return request.auth != null;
}
/**
* Returns the survey with the specified id.
*/
function getSurvey(surveyId) {
return firestore.get(/databases/(default)/documents/surveys/$(surveyId)).data;
}
/**
* Returns true iff all authenticated users can read and contribute
* data to the specified survey.
*/
function isUnlistedOrPublic(survey) {
return survey["8"] in [
2 /* UNLISTED */,
3 /* PUBLIC */
];
}
/**
* Returns true if the current user has one of the specified roles in the
* given survey.
*/
function isOneOf(survey, roles) {
return survey["4"][request.auth.token.email] in roles;
}
/**
* Returns true iff the user with the user's email can read the specified
* survey.
*/
function canViewSurvey(surveyId) {
let survey = getSurvey(surveyId);
return survey != null && isSignedIn() &&
(isUnlistedOrPublic(survey) || survey["4"][request.auth.token.email] != null);
}
/**
* Returns true iff the current user with the given email can contribute LOIs
* and submissions to the specified survey.
*/
function canCollectData(surveyId) {
let survey = getSurvey(surveyId);
return survey != null && isSignedIn() &&
(isUnlistedOrPublic(survey) || isOneOf(survey, [
2 /* DATA_COLLECTOR */,
3 /* SURVEY_ORGANIZER */
]));
}
match /temp/{userId}/{allPaths=**} {
// Only the owning user can read their own temporary files.
allow read: if isSignedIn() && request.auth.uid == userId;
}
match /offline-imagery/{allPaths=**} {
// All authenticated users can read.
allow read: if isSignedIn();
}
match /user-media/surveys/{surveyId}/{allPaths=**} {
// Only users with permission to access the survey can read media.
allow read: if canViewSurvey(surveyId);
// Only users with permission to contribute data to the survey can create/update media.
allow create, write: if canCollectData(surveyId);
}
}
}