From d3c297e29dea59596b45b45b28e8549436fc0f7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Thu, 17 Mar 2022 01:29:46 +0200 Subject: [PATCH] Remove dossiersServiceResolver from PermissionsService [3] --- ...dossier-overview-bulk-actions.component.ts | 10 +- .../dossier-overview/config.service.ts | 5 +- .../file-actions/file-actions.component.ts | 12 +- .../comments/comments.component.html | 54 ++++----- .../components/comments/comments.component.ts | 4 +- .../page-exclusion.component.ts | 4 +- .../file-preview-screen.component.ts | 7 +- .../services/file-preview-state.service.ts | 7 +- .../src/app/services/permissions.service.ts | 103 +++++++----------- 9 files changed, 98 insertions(+), 108 deletions(-) diff --git a/apps/red-ui/src/app/modules/dossier-overview/components/bulk-actions/dossier-overview-bulk-actions.component.ts b/apps/red-ui/src/app/modules/dossier-overview/components/bulk-actions/dossier-overview-bulk-actions.component.ts index 47edcdc94..a23516632 100644 --- a/apps/red-ui/src/app/modules/dossier-overview/components/bulk-actions/dossier-overview-bulk-actions.component.ts +++ b/apps/red-ui/src/app/modules/dossier-overview/components/bulk-actions/dossier-overview-bulk-actions.component.ts @@ -187,15 +187,15 @@ export class DossierOverviewBulkActionsComponent implements OnChanges { this.#canReanalyse = this._permissionsService.canReanalyseFile(this.selectedFiles, this.dossier); - this.#canDisableAutoAnalysis = this._permissionsService.canDisableAutoAnalysis(this.selectedFiles); + this.#canDisableAutoAnalysis = this._permissionsService.canDisableAutoAnalysis(this.selectedFiles, this.dossier); - this.#canEnableAutoAnalysis = this._permissionsService.canEnableAutoAnalysis(this.selectedFiles); + this.#canEnableAutoAnalysis = this._permissionsService.canEnableAutoAnalysis(this.selectedFiles, this.dossier); - this.#canToggleAnalysis = this._permissionsService.canToggleAnalysis(this.selectedFiles); + this.#canToggleAnalysis = this._permissionsService.canToggleAnalysis(this.selectedFiles, this.dossier); this.#canOcr = this._permissionsService.canOcrFile(this.selectedFiles, this.dossier); - this.#canSetToNew = this._permissionsService.canSetToNew(this.selectedFiles) && !isWorkflow; + this.#canSetToNew = this._permissionsService.canSetToNew(this.selectedFiles, this.dossier) && !isWorkflow; this.#canSetToUnderReview = this._permissionsService.canSetUnderReview(this.selectedFiles, this.dossier) && !isWorkflow; @@ -203,7 +203,7 @@ export class DossierOverviewBulkActionsComponent implements OnChanges { this.#isReadyForApproval = this._permissionsService.isReadyForApproval(this.selectedFiles, this.dossier) && !isWorkflow; - this.#canApprove = this._permissionsService.canBeApproved(this.selectedFiles) && !isWorkflow; + this.#canApprove = this._permissionsService.canBeApproved(this.selectedFiles, this.dossier) && !isWorkflow; this.#canUndoApproval = this._permissionsService.canUndoApproval(this.selectedFiles, this.dossier) && !isWorkflow; diff --git a/apps/red-ui/src/app/modules/dossier-overview/config.service.ts b/apps/red-ui/src/app/modules/dossier-overview/config.service.ts index 7af9c5988..930631639 100644 --- a/apps/red-ui/src/app/modules/dossier-overview/config.service.ts +++ b/apps/red-ui/src/app/modules/dossier-overview/config.service.ts @@ -58,7 +58,7 @@ export class ConfigService { label: workflowFileStatusTranslations[WorkflowFileStatuses.NEW], key: WorkflowFileStatuses.NEW, enterFn: (files: File[]) => this._bulkActionsService.setToNew(files), - enterPredicate: (files: File[]) => this._permissionsService.canSetToNew(files), + enterPredicate: (files: File[]) => this._permissionsService.canSetToNew(files, dossier), color: '#D3D5DA', entities: new BehaviorSubject([]), }, @@ -93,7 +93,8 @@ export class ConfigService { label: workflowFileStatusTranslations[WorkflowFileStatuses.APPROVED], enterFn: (files: File[]) => this._bulkActionsService.approve(files), enterPredicate: (files: File[]) => - this._permissionsService.isReadyForApproval(files, dossier) && this._permissionsService.canBeApproved(files), + this._permissionsService.isReadyForApproval(files, dossier) && + this._permissionsService.canBeApproved(files, dossier), key: WorkflowFileStatuses.APPROVED, color: '#48C9F7', entities: new BehaviorSubject([]), diff --git a/apps/red-ui/src/app/modules/dossier/shared/components/file-actions/file-actions.component.ts b/apps/red-ui/src/app/modules/dossier/shared/components/file-actions/file-actions.component.ts index 4374b7c81..86609ee66 100644 --- a/apps/red-ui/src/app/modules/dossier/shared/components/file-actions/file-actions.component.ts +++ b/apps/red-ui/src/app/modules/dossier/shared/components/file-actions/file-actions.component.ts @@ -437,19 +437,19 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy, this.buttonType = this.isFilePreview ? CircleButtonTypes.default : CircleButtonTypes.dark; this.toggleTooltip = this._toggleTooltip; - this.showSetToNew = this._permissionsService.canSetToNew(this.file) && !this.isDossierOverviewWorkflow; + this.showSetToNew = this._permissionsService.canSetToNew(this.file, this.dossier) && !this.isDossierOverviewWorkflow; this.showUndoApproval = this._permissionsService.canUndoApproval(this.file, this.dossier) && !this.isDossierOverviewWorkflow; this.showUnderReview = this._permissionsService.canSetUnderReview(this.file, this.dossier) && !this.isDossierOverviewWorkflow; this.showUnderApproval = this._permissionsService.canSetUnderApproval(this.file, this.dossier) && !this.isDossierOverviewWorkflow; this.showApprove = this._permissionsService.isReadyForApproval(this.file, this.dossier) && !this.isDossierOverviewWorkflow; - this.canToggleAnalysis = this._permissionsService.canToggleAnalysis(this.file); - this.showToggleAnalysis = this._permissionsService.showToggleAnalysis(this.file); + this.canToggleAnalysis = this._permissionsService.canToggleAnalysis(this.file, this.dossier); + this.showToggleAnalysis = this._permissionsService.showToggleAnalysis(this.dossier); this.showDelete = this._permissionsService.canDeleteFile(this.file, this.dossier); this.showOCR = this._permissionsService.canOcrFile(this.file, this.dossier); this.canReanalyse = this._permissionsService.canReanalyseFile(this.file, this.dossier); - this.canDisableAutoAnalysis = this._permissionsService.canDisableAutoAnalysis([this.file]); - this.canEnableAutoAnalysis = this._permissionsService.canEnableAutoAnalysis([this.file]); + this.canDisableAutoAnalysis = this._permissionsService.canDisableAutoAnalysis([this.file], this.dossier); + this.canEnableAutoAnalysis = this._permissionsService.canEnableAutoAnalysis([this.file], this.dossier); this.showStatusBar = !this.file.isError && !this.file.isUnprocessed && this.isDossierOverviewList; @@ -459,7 +459,7 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy, this._permissionsService.canUnassignUser(this.file, this.dossier)) && this.isDossierOverview; - this.showImportRedactions = this._permissionsService.canImportRedactions(this.file); + this.showImportRedactions = this._permissionsService.canImportRedactions(this.file, this.dossier); const showReanalyse = this.canReanalyse || this.file.excludedFromAutomaticAnalysis || this.analysisForced; diff --git a/apps/red-ui/src/app/modules/file-preview/components/comments/comments.component.html b/apps/red-ui/src/app/modules/file-preview/components/comments/comments.component.html index 427cebe5c..c4df98785 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/comments/comments.component.html +++ b/apps/red-ui/src/app/modules/file-preview/components/comments/comments.component.html @@ -1,34 +1,36 @@ -
-
-
- {{ comment.user | name }} - {{ comment.date | date: 'sophisticatedDate' }} + +
+
+
+ {{ comment.user | name }} + {{ comment.date | date: 'sophisticatedDate' }} +
+ +
+ +
-
- -
+
{{ comment.text }}
-
{{ comment.text }}
-
- - + +
diff --git a/apps/red-ui/src/app/modules/file-preview/components/comments/comments.component.ts b/apps/red-ui/src/app/modules/file-preview/components/comments/comments.component.ts index 7af877e30..da2574a61 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/comments/comments.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/components/comments/comments.component.ts @@ -1,5 +1,5 @@ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, HostBinding, Input, OnChanges, ViewChild } from '@angular/core'; -import { File, IComment } from '@red/domain'; +import { Dossier, File, IComment } from '@red/domain'; import { ManualAnnotationService } from '@services/manual-annotation.service'; import { AnnotationWrapper } from '@models/file/annotation.wrapper'; import { UserService } from '@services/user.service'; @@ -20,6 +20,7 @@ export class CommentsComponent extends AutoUnsubscribe implements OnChanges { @Input() annotation: AnnotationWrapper; readonly trackBy = trackByFactory(); readonly file$: Observable; + readonly dossier$: Observable; @HostBinding('class.hidden') _hidden = true; @ViewChild(InputWithActionComponent) private readonly _input: InputWithActionComponent; @@ -34,6 +35,7 @@ export class CommentsComponent extends AutoUnsubscribe implements OnChanges { ) { super(); this.file$ = _stateService.file$; + this.dossier$ = _stateService.dossier$; } ngOnChanges() { diff --git a/apps/red-ui/src/app/modules/file-preview/components/page-exclusion/page-exclusion.component.ts b/apps/red-ui/src/app/modules/file-preview/components/page-exclusion/page-exclusion.component.ts index c0d1a0e23..518e180f1 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/page-exclusion/page-exclusion.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/components/page-exclusion/page-exclusion.component.ts @@ -28,8 +28,8 @@ export class PageExclusionComponent { private readonly _loadingService: LoadingService, private readonly _state: FilePreviewStateService, ) { - this.canExcludePages$ = this._state.file$.pipe( - map(file => permissionsService.canExcludePages(file)), + this.canExcludePages$ = combineLatest([this._state.file$, this._state.dossier$]).pipe( + map(([file, dossier]) => permissionsService.canExcludePages(file, dossier)), shareLast(), ); this.excludedRanges$ = this._excludedRanges$; diff --git a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts index 6fa9e83cd..b4203e266 100644 --- a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts @@ -137,8 +137,11 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni private get _canPerformAnnotationActions$() { const viewMode$ = this._viewModeService.viewMode$.pipe(tap(() => this.#deactivateMultiSelect())); - return combineLatest([this.stateService.file$, viewMode$, this._viewModeService.compareMode$]).pipe( - map(([file, viewMode]) => this.permissionsService.canPerformAnnotationActions(file) && viewMode === 'STANDARD'), + return combineLatest([this.stateService.file$, this.stateService.dossier$, viewMode$, this._viewModeService.compareMode$]).pipe( + map( + ([file, dossier, viewMode]) => + this.permissionsService.canPerformAnnotationActions(file, dossier) && viewMode === 'STANDARD', + ), shareDistinctLast(), ); } diff --git a/apps/red-ui/src/app/modules/file-preview/services/file-preview-state.service.ts b/apps/red-ui/src/app/modules/file-preview/services/file-preview-state.service.ts index 9a26097b9..683bc06a9 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/file-preview-state.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/file-preview-state.service.ts @@ -1,5 +1,5 @@ import { Injectable, Injector } from '@angular/core'; -import { firstValueFrom, from, Observable, pairwise, switchMap } from 'rxjs'; +import { combineLatest, firstValueFrom, from, Observable, pairwise, switchMap } from 'rxjs'; import { Dossier, File } from '@red/domain'; import { ActivatedRoute } from '@angular/router'; import { FilesMapService } from '@services/entity-services/files-map.service'; @@ -37,7 +37,10 @@ export class FilePreviewStateService { this.dossier$ = this._dossiersService.getEntityChanged$(this.dossierId); this.file$ = _filesMapService.watch$(this.dossierId, this.fileId); - [this.isReadonly$, this.isWritable$] = boolFactory(this.file$, file => !_permissionsService.canPerformAnnotationActions(file)); + [this.isReadonly$, this.isWritable$] = boolFactory( + combineLatest([this.file$, this.dossier$]), + ([file, dossier]) => !_permissionsService.canPerformAnnotationActions(file, dossier), + ); this.blob$ = this.#blob$; } diff --git a/apps/red-ui/src/app/services/permissions.service.ts b/apps/red-ui/src/app/services/permissions.service.ts index a113be62a..071ebb0ef 100644 --- a/apps/red-ui/src/app/services/permissions.service.ts +++ b/apps/red-ui/src/app/services/permissions.service.ts @@ -1,9 +1,7 @@ import { Injectable, Injector } from '@angular/core'; import { UserService } from './user.service'; import { Dossier, File, IComment, IDossier } from '@red/domain'; -import { DossiersService } from '@services/dossiers/dossiers.service'; import { ActivatedRoute } from '@angular/router'; -import { dossiersServiceResolver } from '@services/entity-services/dossiers.service.provider'; import { FilesMapService } from '@services/entity-services/files-map.service'; import { FeaturesService } from '@services/features.service'; import { DOSSIERS_ARCHIVE } from '@utils/constants'; @@ -18,10 +16,6 @@ export class PermissionsService { private readonly _featuresService: FeaturesService, ) {} - private get _dossiersService(): DossiersService { - return dossiersServiceResolver(this._injector); - } - canPerformDossierStatesActions(user = this._userService.currentUser): boolean { return user.isAdmin; } @@ -44,20 +38,19 @@ export class PermissionsService { canEditFileAttributes(file: File, dossier: Dossier): boolean { return ( - this._isActive(file) && + dossier.isActive && (((file.isUnderReview || file.isNew) && this.isDossierMember(dossier)) || (file.isUnderApproval && this.isApprover(dossier))) ); } - canToggleAnalysis(file: File | File[]): boolean { + canToggleAnalysis(file: File | File[], dossier: Dossier): boolean { const files = file instanceof File ? [file] : file; const sameState = new Set(files.map(f => f.excluded)).size === 1; - return sameState && files.reduce((acc, _file) => this._canToggleAnalysis(_file) && acc, true); + return sameState && files.reduce((acc, _file) => this._canToggleAnalysis(_file, dossier) && acc, true); } - showToggleAnalysis(file: File | File[]): boolean { - const files = file instanceof File ? [file] : file; - return this._isActive(files[0]); + showToggleAnalysis(dossier: Dossier): boolean { + return dossier.isActive; } canReanalyseFile(file: File | File[], dossier: Dossier): boolean { @@ -65,12 +58,12 @@ export class PermissionsService { return files.reduce((acc, _file) => this._canReanalyseFile(_file, dossier) && acc, true); } - canEnableAutoAnalysis(files: File[]): boolean { - return files.reduce((acc, _file) => this._canEnableAutoAnalysis(_file) && acc, true); + canEnableAutoAnalysis(files: File[], dossier: Dossier): boolean { + return files.reduce((acc, _file) => this._canEnableAutoAnalysis(_file, dossier) && acc, true); } - canDisableAutoAnalysis(files: File[]): boolean { - return files.reduce((acc, _file) => this._canDisableAutoAnalysis(_file) && acc, true); + canDisableAutoAnalysis(files: File[], dossier: Dossier): boolean { + return files.reduce((acc, _file) => this._canDisableAutoAnalysis(_file, dossier) && acc, true); } isFileAssignee(file: File): boolean { @@ -106,19 +99,19 @@ export class PermissionsService { return files.reduce((acc, _file) => this._canUnassignUser(_file, dossier) && acc, true); } - canSetToNew(file: File | File[]): boolean { + canSetToNew(file: File | File[], dossier: Dossier): boolean { const files = file instanceof File ? [file] : file; - return files.reduce((acc, _file) => this._canSetToNew(_file) && acc, true); + return files.reduce((acc, _file) => this._canSetToNew(_file, dossier) && acc, true); } canSetUnderReview(file: File | File[], dossier: Dossier): boolean { const files = file instanceof File ? [file] : file; - return this.isApprover(dossier) && files.reduce((acc, _file) => this._canSetUnderReview(_file) && acc, true); + return this.isApprover(dossier) && files.reduce((acc, _file) => this._canSetUnderReview(_file, dossier) && acc, true); } - canBeApproved(file: File | File[]): boolean { + canBeApproved(file: File | File[], dossier: Dossier): boolean { const files = file instanceof File ? [file] : file; - return files.reduce((acc, _file) => this._canBeApproved(_file) && acc, true); + return files.reduce((acc, _file) => this._canBeApproved(_file, dossier) && acc, true); } isReadyForApproval(files: File | File[], dossier: Dossier): boolean { @@ -142,9 +135,9 @@ export class PermissionsService { return dossier.memberIds.includes(user.id); } - canPerformAnnotationActions(file: File): boolean { + canPerformAnnotationActions(file: File, dossier: Dossier): boolean { return ( - this._isActive(file) && + dossier.isActive && !file.isOcrProcessing && !file.excluded && (file.isUnderReview || file.isUnderApproval) && @@ -202,29 +195,28 @@ export class PermissionsService { return user.isAdmin; } - canAddComment(file: File): boolean { - return (this.isFileAssignee(file) || this.isApprover(this._getDossier(file))) && !file.isApproved; + canAddComment(file: File, dossier: Dossier): boolean { + return (this.isFileAssignee(file) || this.isApprover(dossier)) && !file.isApproved; } - canExcludePages(file: File): boolean { - return this.canPerformAnnotationActions(file); + canExcludePages(file: File, dossier: Dossier): boolean { + return this.canPerformAnnotationActions(file, dossier); } - canDeleteComment(comment: IComment, file: File) { - const dossier = this._getDossier(file); + canDeleteComment(comment: IComment, file: File, dossier: Dossier) { return (comment.user === this._userService.currentUser.id || this.isApprover(dossier)) && !file.isApproved; } - canImportRedactions(file: File) { - return this._isActive(file) && (this.isFileAssignee(file) || this.isApprover(this._getDossier(file))) && !file.isApproved; + canImportRedactions(file: File, dossier: Dossier) { + return dossier.isActive && (this.isFileAssignee(file) || this.isApprover(dossier)) && !file.isApproved; } private _canOcrFile(file: File, dossier: Dossier): boolean { return dossier.isActive && file.canBeOCRed; } - private _canToggleAnalysis(file: File): boolean { - return this._isActive(file) && this.isFileAssignee(file) && (file.isNew || file.isUnderReview || file.isUnderApproval); + private _canToggleAnalysis(file: File, dossier: Dossier): boolean { + return dossier.isActive && this.isFileAssignee(file) && (file.isNew || file.isUnderReview || file.isUnderApproval); } // https://jira.iqser.com/browse/RED-2787 @@ -239,21 +231,18 @@ export class PermissionsService { } private _canReanalyseFile(file: File, dossier: Dossier): boolean { - return this._isActive(file) && this.isReviewerOrApprover(file, dossier) && file.analysisRequired; + return dossier.isActive && this.isReviewerOrApprover(file, dossier) && file.analysisRequired; } - private _canEnableAutoAnalysis(file: File): boolean { + private _canEnableAutoAnalysis(file: File, dossier: Dossier): boolean { return ( - this._isActive(file) && - file.excludedFromAutomaticAnalysis && - file.assignee === this._userService.currentUser.id && - !file.isApproved + dossier.isActive && file.excludedFromAutomaticAnalysis && file.assignee === this._userService.currentUser.id && !file.isApproved ); } - private _canDisableAutoAnalysis(file: File): boolean { + private _canDisableAutoAnalysis(file: File, dossier: Dossier): boolean { return ( - this._isActive(file) && + dossier.isActive && !file.excludedFromAutomaticAnalysis && file.assignee === this._userService.currentUser.id && !file.isApproved @@ -262,24 +251,24 @@ export class PermissionsService { private _canAssignToSelf(file: File, dossier: Dossier): boolean { const precondition = - this._isActive(file) && this.isDossierMember(dossier) && !this.isFileAssignee(file) && !file.isError && !file.isProcessing; + dossier.isActive && this.isDossierMember(dossier) && !this.isFileAssignee(file) && !file.isError && !file.isProcessing; return precondition && (file.isNew || file.isUnderReview || (file.isUnderApproval && this.isApprover(dossier))); } private _canSetUnderApproval(file: File, dossier: Dossier): boolean { - return this._isActive(file) && file.isUnderReview && this.isReviewerOrApprover(file, dossier); + return dossier.isActive && file.isUnderReview && this.isReviewerOrApprover(file, dossier); } private _canUndoApproval(file: File, dossier: Dossier): boolean { - return this._isActive(file) && file.isApproved && this.isApprover(dossier); + return dossier.isActive && file.isApproved && this.isApprover(dossier); } - private _canBeApproved(file: File): boolean { - return this._isActive(file) && file.canBeApproved; + private _canBeApproved(file: File, dossier: Dossier): boolean { + return dossier.isActive && file.canBeApproved; } private _canAssignUser(file: File, dossier: Dossier) { - const precondition = this._isActive(file) && !file.isProcessing && !file.isError && !file.isApproved && this.isApprover(dossier); + const precondition = dossier.isActive && !file.isProcessing && !file.isError && !file.isApproved && this.isApprover(dossier); if (precondition) { if ((file.isNew || file.isUnderReview) && dossier.hasReviewers) { @@ -293,24 +282,14 @@ export class PermissionsService { } private _canUnassignUser(file: File, dossier: Dossier) { - return ( - this._isActive(file) && (file.isUnderReview || file.isUnderApproval) && (this.isFileAssignee(file) || this.isApprover(dossier)) - ); + return dossier.isActive && (file.isUnderReview || file.isUnderApproval) && (this.isFileAssignee(file) || this.isApprover(dossier)); } - private _canSetToNew(file: File): boolean { - return this._isActive(file) && file.isUnderReview; + private _canSetToNew(file: File, dossier: Dossier): boolean { + return dossier.isActive && file.isUnderReview; } - private _canSetUnderReview(file: File): boolean { - return this._isActive(file) && file.isUnderApproval; - } - - private _getDossier(file: File): Dossier { - return this._dossiersService.find(file.dossierId); - } - - private _isActive(file: File): boolean { - return this._getDossier(file).isActive; + private _canSetUnderReview(file: File, dossier: Dossier): boolean { + return dossier.isActive && file.isUnderApproval; } }