|
30 | 30 | * data to the specified survey.
|
31 | 31 | */
|
32 | 32 | function isUnlistedOrPublic(survey) {
|
33 |
| - return survey["8"] in [ |
| 33 | + return survey["8"] in [ |
34 | 34 | 2 /* UNLISTED */,
|
35 | 35 | 3 /* PUBLIC */
|
36 | 36 | ];
|
37 | 37 | }
|
38 | 38 |
|
| 39 | + /** |
| 40 | + * Returns true iff data collectors can see each others' data. |
| 41 | + */ |
| 42 | + function canViewDataCollectedByOthers(survey) { |
| 43 | + return survey["9"] == 2 /* ALL_SURVEY_PARTICIPANTS */ |
| 44 | + } |
| 45 | +
|
39 | 46 | /**
|
40 | 47 | * Returns the current user's role in the given survey.
|
41 | 48 | */
|
|
67 | 74 | }
|
68 | 75 |
|
69 | 76 | /**
|
70 |
| - * Returns true iff the user with the given email can read the specified |
| 77 | + * Returns true iff the user with the user's email can read the specified |
71 | 78 | * survey.
|
72 | 79 | */
|
73 | 80 | function canViewSurvey(survey) {
|
74 | 81 | return canAccess() &&
|
75 | 82 | (isUnlistedOrPublic(survey) || getRole(survey) != null);
|
76 | 83 | }
|
77 | 84 |
|
| 85 | + /** |
| 86 | + * Returns true iff user can see each other's lois in the specified |
| 87 | + * survey. |
| 88 | + */ |
| 89 | + function canViewLoi(survey, loi) { |
| 90 | + return canViewSurvey(survey) && (isLoiOwner(loi) || canViewDataCollectedByOthers(survey)); |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Returns true iff user can see each other's submissions in the specified |
| 95 | + * survey. |
| 96 | + */ |
| 97 | + function canViewSubmission(survey, submission) { |
| 98 | + return canViewSurvey(survey) && (isSubmissionOwner(submission) || canViewDataCollectedByOthers(survey)); |
| 99 | + } |
| 100 | +
|
78 | 101 | /**
|
79 | 102 | * Returns true if the current user has one of the specified roles in the
|
80 | 103 | * given survey.
|
|
95 | 118 | }
|
96 | 119 |
|
97 | 120 | /**
|
98 |
| - * Returns true iff the current user with the given email can contribute LOIs |
| 121 | + * Returns true iff the current user with the given email can contribute LOIs |
99 | 122 | * and submissions to the specified survey.
|
100 | 123 | */
|
101 | 124 | function canCollectData(survey) {
|
|
149 | 172 | allow read: if request.auth != null;
|
150 | 173 | }
|
151 | 174 |
|
152 |
| - // Apply passlist and survey-level ACLs to LOI documents. |
| 175 | + // Apply passlist and survey-level General Access and/or ACLs to LOI documents. |
153 | 176 | match /surveys/{surveyId}/lois/{loiId} {
|
154 |
| - // Allow if user has has read access to the survey. |
155 |
| - allow read: if canViewSurvey(getSurvey(surveyId)); |
| 177 | + // Allow if user has read access to the survey and the LOI. |
| 178 | + allow read: if canViewLoi(getSurvey(surveyId), request.resource); |
156 | 179 | // Allow if user is owner of the new LOI and can collect data.
|
157 | 180 | allow create: if isLoiOwner(request.resource) && canCollectData(getSurvey(surveyId));
|
158 | 181 | // Allow if user is owner of the existing LOI or can manage survey.
|
159 | 182 | allow write: if isLoiOwner(resource) || canManageSurvey(getSurvey(surveyId));
|
160 | 183 | }
|
161 | 184 |
|
162 |
| - // Apply passlist and survey-level ACLs to submission documents. |
| 185 | + // Apply passlist and survey-level General Access and/or ACLs to submission documents. |
163 | 186 | match /surveys/{surveyId}/submissions/{submissionId} {
|
164 |
| - // Allow if user has has read access to the survey. |
165 |
| - allow read: if canViewSurvey(getSurvey(surveyId)); |
| 187 | + // Allow if user has read access to the survey and the submission. |
| 188 | + allow read: if canViewSubmission(getSurvey(surveyId), request.resource); |
166 | 189 | // Allow if user is owner of the new submission and can collect data.
|
167 | 190 | allow create: if isSubmissionOwner(request.resource) && canCollectData(getSurvey(surveyId));
|
168 | 191 | // Allow if user is owner of the existing submission or can manage survey.
|
|
171 | 194 |
|
172 | 195 | // Apply passlist and survey-level ACLs to job documents.
|
173 | 196 | match /surveys/{surveyId}/jobs/{jobId} {
|
174 |
| - // Allow if user has has read access to the survey. |
| 197 | + // Allow if user has read access to the survey. |
175 | 198 | allow read: if canViewSurvey(getSurvey(surveyId));
|
176 | 199 | // Allow if user can manage survey.
|
177 | 200 | allow create, write: if canManageSurvey(getSurvey(surveyId));
|
|
0 commit comments