Skip to content

Commit 5905871

Browse files
rfontanarosagino-m
andauthored
Added site/submission filter based on survey visibility setting (#2215)
Co-authored-by: Gino Miceli <[email protected]>
1 parent 6cb18d4 commit 5905871

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

web/src/app/services/data-store/data-store.service.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -433,14 +433,14 @@ export class DataStoreService {
433433
*
434434
* @param survey the survey instance.
435435
* @param userEmail the email of the user to filter the results.
436-
* @param canManageSurvey a flag indicating whether the user has survey organizer or owner level permissions of the survey.
436+
* @param canViewAll a flag indicating whether the user has permission to view all LOIs for this survey.
437437
*/
438438
getAccessibleLois$(
439439
{id: surveyId}: Survey,
440440
userId: string,
441-
canManageSurvey: boolean
441+
canViewAll: boolean
442442
): Observable<List<LocationOfInterest>> {
443-
if (canManageSurvey) {
443+
if (canViewAll) {
444444
return this.db
445445
.collection(`${SURVEYS_COLLECTION_NAME}/${surveyId}/lois`)
446446
.valueChanges({idField: 'id'})
@@ -477,17 +477,17 @@ export class DataStoreService {
477477
* @param survey the survey instance.
478478
* @param loi the loi instance.
479479
* @param userEmail the email of the user to filter the results.
480-
* @param canManageSurvey a flag indicating whether the user has survey organizer or owner level permissions of the survey.
480+
* @param canViewAll a flag indicating whether the user has permission to view all LOIs for this survey.
481481
*/
482482
getAccessibleSubmissions$(
483483
survey: Survey,
484484
loi: LocationOfInterest,
485485
userId: string,
486-
canManageSurvey: boolean
486+
canViewAll: boolean
487487
): Observable<List<Submission>> {
488488
return this.db
489489
.collection(`${SURVEYS_COLLECTION_NAME}/${survey.id}/submissions`, ref =>
490-
this.canViewSubmissions(ref, loi.id, userId, canManageSurvey)
490+
this.canViewSubmissions(ref, loi.id, userId, canViewAll)
491491
)
492492
.valueChanges({idField: 'id'})
493493
.pipe(
@@ -621,10 +621,10 @@ export class DataStoreService {
621621
ref: CollectionReference,
622622
loiId: string,
623623
userId: string,
624-
canManageSurvey: boolean
624+
canViewAll: boolean
625625
) {
626626
const query = ref.where(sb.loiId, '==', loiId);
627627

628-
return canManageSurvey ? query : query.where(sb.ownerId, '==', userId);
628+
return canViewAll ? query : query.where(sb.ownerId, '==', userId);
629629
}
630630
}

web/src/app/services/loi/loi.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {map, switchMap} from 'rxjs/operators';
2121

2222
import {GeometryType} from 'app/models/geometry/geometry';
2323
import {LocationOfInterest} from 'app/models/loi.model';
24-
import {SurveyState} from 'app/models/survey.model';
24+
import {SurveyDataVisibility, SurveyState} from 'app/models/survey.model';
2525
import {AuthService} from 'app/services/auth/auth.service';
2626
import {DataStoreService} from 'app/services/data-store/data-store.service';
2727
import {SurveyService} from 'app/services/survey/survey.service';
@@ -52,7 +52,9 @@ export class LocationOfInterestService {
5252
: this.dataStore.getAccessibleLois$(
5353
survey,
5454
user.id,
55-
this.surveyService.canManageSurvey()
55+
this.surveyService.canManageSurvey() ||
56+
survey.dataVisibility ===
57+
SurveyDataVisibility.ALL_SURVEY_PARTICIPANTS
5658
)
5759
)
5860
)

web/src/app/services/submission/submission.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {AuditInfo} from 'app/models/audit-info.model';
2323
import {LocationOfInterest} from 'app/models/loi.model';
2424
import {Result} from 'app/models/submission/result.model';
2525
import {Submission} from 'app/models/submission/submission.model';
26-
import {Survey} from 'app/models/survey.model';
26+
import {Survey, SurveyDataVisibility} from 'app/models/survey.model';
2727
import {User} from 'app/models/user.model';
2828
import {AuthService} from 'app/services/auth/auth.service';
2929
import {DataStoreService} from 'app/services/data-store/data-store.service';
@@ -63,7 +63,9 @@ export class SubmissionService {
6363
survey,
6464
loi,
6565
user.id,
66-
this.surveyService.canManageSurvey()
66+
this.surveyService.canManageSurvey() ||
67+
survey.dataVisibility ===
68+
SurveyDataVisibility.ALL_SURVEY_PARTICIPANTS
6769
)
6870
)
6971
)

0 commit comments

Comments
 (0)