private setAccess()

in pathology/viewer/src/components/cohorts-page/cohorts-page.component.ts [450:494]


  private setAccess(
      pathologyCohort: PathologyCohort,
      currentUser: string,
      ): void {
    const cohortInfo: CohortInfo =
        this.cohortService.pathologyCohortToCohortInfo(pathologyCohort);

    const foundUser = (pathologyCohort.userAccess ??
                       []).find(({userEmail}) => userEmail === currentUser);
    if (!foundUser) {
      this.resetAccess();
    }

    const cohortAccess: PathologyCohortAccess =
        pathologyCohort?.cohortMetadata?.cohortAccess ??
        'PATHOLOGY_COHORT_ACCESS_RESTRICTED';

    const isOpenEdit = cohortAccess === 'PATHOLOGY_COHORT_ACCESS_OPEN_EDIT';
    const isOpenViewOnly =
        cohortAccess === 'PATHOLOGY_COHORT_ACCESS_OPEN_VIEW_ONLY';

    const isOwner = !!foundUser &&
        foundUser.accessRole === 'PATHOLOGY_USER_ACCESS_ROLE_OWNER';
    const isAdmin = !!foundUser &&
        foundUser.accessRole === 'PATHOLOGY_USER_ACCESS_ROLE_ADMIN';
    const isOwnerOrAdmin = isOwner || isAdmin;
    const isEditor = !!foundUser &&
            foundUser.accessRole === 'PATHOLOGY_USER_ACCESS_ROLE_EDITOR' ||
        isOpenEdit;
    const isViewer = (!isEditor && !isOwnerOrAdmin) &&
        (!!foundUser &&
             foundUser.accessRole === 'PATHOLOGY_USER_ACCESS_ROLE_VIEWER' ||
         isOpenViewOnly);

    this.isViewOnly = isViewer && !isOpenEdit;
    this.allowAppending = (isOwnerOrAdmin || isEditor) &&
        !cohortInfo?.isExported && !cohortInfo?.isDeid;
    this.allowRemoving = isOwnerOrAdmin || isEditor;
    this.allowDeleting = isOwnerOrAdmin;
    this.allowEditingFields = (isOwnerOrAdmin || isEditor);
    this.allowSharing = isOwnerOrAdmin;
    this.allowDeid = cohortInfo?.isDeid === false && !isViewer;
    this.allowExport = !isViewer;
    this.isShared = cohortInfo?.isShared ?? false;
  }