From 9692f449b72aa71d862d6c6fe6c7160e6c523170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Thu, 17 Mar 2022 00:41:55 +0200 Subject: [PATCH 1/4] Remove dossiersServiceResolver from PermissionsService [1] --- ...dossier-overview-bulk-actions.component.ts | 4 +-- .../table-item/table-item.component.html | 8 ++++- .../table-item/table-item.component.ts | 10 +++--- .../workflow-item.component.html | 1 + .../workflow-item/workflow-item.component.ts | 11 +++--- .../dossier-overview/config.service.ts | 6 ++-- .../dossier-overview-screen.component.html | 7 +++- .../dossier-overview-screen.component.ts | 36 +++++++++---------- .../file-actions/file-actions.component.ts | 9 ++--- .../annotation-details.component.ts | 6 ++-- .../file-preview-screen.component.html | 1 + .../src/app/services/permissions.service.ts | 23 +++++------- 12 files changed, 66 insertions(+), 56 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 77b2802d1..dfa7e203b 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 @@ -182,7 +182,7 @@ export class DossierOverviewBulkActionsComponent implements OnChanges { this.#canDelete = this._permissionsService.canDeleteFile(this.selectedFiles); - this.#canReanalyse = this._permissionsService.canReanalyseFile(this.selectedFiles); + this.#canReanalyse = this._permissionsService.canReanalyseFile(this.selectedFiles, this.dossier); this.#canDisableAutoAnalysis = this._permissionsService.canDisableAutoAnalysis(this.selectedFiles); @@ -196,7 +196,7 @@ export class DossierOverviewBulkActionsComponent implements OnChanges { this.#canSetToUnderReview = this._permissionsService.canSetUnderReview(this.selectedFiles) && !isWorkflow; - this.#canSetToUnderApproval = this._permissionsService.canSetUnderApproval(this.selectedFiles) && !isWorkflow; + this.#canSetToUnderApproval = this._permissionsService.canSetUnderApproval(this.selectedFiles, this.dossier) && !isWorkflow; this.#isReadyForApproval = this._permissionsService.isReadyForApproval(this.selectedFiles) && !isWorkflow; diff --git a/apps/red-ui/src/app/modules/dossier-overview/components/table-item/table-item.component.html b/apps/red-ui/src/app/modules/dossier-overview/components/table-item/table-item.component.html index 57dd7229a..5e8f03903 100644 --- a/apps/red-ui/src/app/modules/dossier-overview/components/table-item/table-item.component.html +++ b/apps/red-ui/src/app/modules/dossier-overview/components/table-item/table-item.component.html @@ -56,5 +56,11 @@ > - + diff --git a/apps/red-ui/src/app/modules/dossier-overview/components/table-item/table-item.component.ts b/apps/red-ui/src/app/modules/dossier-overview/components/table-item/table-item.component.ts index 33df01b32..657dead78 100644 --- a/apps/red-ui/src/app/modules/dossier-overview/components/table-item/table-item.component.ts +++ b/apps/red-ui/src/app/modules/dossier-overview/components/table-item/table-item.component.ts @@ -1,15 +1,15 @@ import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; -import { File, IFileAttributeConfig } from '@red/domain'; -import { Required } from '@iqser/common-ui'; +import { Dossier, File, IFileAttributeConfig } from '@red/domain'; @Component({ - selector: 'redaction-table-item', + selector: 'redaction-table-item [file] [dossier] [displayedAttributes] [dossierTemplateId]', templateUrl: './table-item.component.html', styleUrls: ['./table-item.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush, }) export class TableItemComponent { - @Input() @Required() file!: File; - @Input() @Required() displayedAttributes!: IFileAttributeConfig[]; + @Input() file: File; + @Input() dossier: Dossier; + @Input() displayedAttributes: IFileAttributeConfig[]; @Input() dossierTemplateId: string; } diff --git a/apps/red-ui/src/app/modules/dossier-overview/components/workflow-item/workflow-item.component.html b/apps/red-ui/src/app/modules/dossier-overview/components/workflow-item/workflow-item.component.html index 4e00dde19..1d1b2c4fa 100644 --- a/apps/red-ui/src/app/modules/dossier-overview/components/workflow-item/workflow-item.component.html +++ b/apps/red-ui/src/app/modules/dossier-overview/components/workflow-item/workflow-item.component.html @@ -25,6 +25,7 @@
{ + workflowConfig(dossier: Dossier): WorkflowConfig { return { columnIdentifierFn: entity => entity.workflowStatus, itemVersionFn: (entity: File) => `${entity.lastUpdated}-${entity.numberOfAnalyses}`, @@ -83,7 +83,7 @@ export class ConfigService { label: workflowFileStatusTranslations[WorkflowFileStatuses.UNDER_APPROVAL], enterFn: (files: File[]) => this._bulkActionsService.setToUnderApproval(files), enterPredicate: (files: File[]) => - this._permissionsService.canSetUnderApproval(files) || this._permissionsService.canUndoApproval(files), + this._permissionsService.canSetUnderApproval(files, dossier) || this._permissionsService.canUndoApproval(files), key: WorkflowFileStatuses.UNDER_APPROVAL, color: '#374C81', entities: new BehaviorSubject([]), diff --git a/apps/red-ui/src/app/modules/dossier-overview/screen/dossier-overview-screen.component.html b/apps/red-ui/src/app/modules/dossier-overview/screen/dossier-overview-screen.component.html index 020770b34..e7cae904d 100644 --- a/apps/red-ui/src/app/modules/dossier-overview/screen/dossier-overview-screen.component.html +++ b/apps/red-ui/src/app/modules/dossier-overview/screen/dossier-overview-screen.component.html @@ -67,6 +67,7 @@ @@ -79,5 +80,9 @@ - + diff --git a/apps/red-ui/src/app/modules/dossier-overview/screen/dossier-overview-screen.component.ts b/apps/red-ui/src/app/modules/dossier-overview/screen/dossier-overview-screen.component.ts index 29244ba09..5b3a1f9d1 100644 --- a/apps/red-ui/src/app/modules/dossier-overview/screen/dossier-overview-screen.component.ts +++ b/apps/red-ui/src/app/modules/dossier-overview/screen/dossier-overview-screen.component.ts @@ -69,11 +69,11 @@ export class DossierOverviewScreenComponent extends ListingComponent imple tableColumnConfigs: readonly TableColumnConfig[]; displayedInFileListAttributes: IFileAttributeConfig[] = []; displayedAttributes: IFileAttributeConfig[] = []; - readonly workflowConfig: WorkflowConfig = this.configService.workflowConfig; + readonly workflowConfig: WorkflowConfig; readonly dossier$: Observable; readonly dossierId: string; - currentDossier: Dossier; dossierTemplateId: string; + #currentDossier: Dossier; @ViewChild('needsWorkFilterTemplate', { read: TemplateRef, static: true }) private readonly _needsWorkFilterTemplate: TemplateRef; @ViewChild('fileInput', { static: true }) private readonly _fileInput: ElementRef; @@ -101,11 +101,15 @@ export class DossierOverviewScreenComponent extends ListingComponent imple ) { super(_injector); this.dossierId = _route.snapshot.paramMap.get(DOSSIER_ID); - this.dossier$ = this._dossiersService - .getEntityChanged$(this.dossierId) - .pipe(tap(dossier => (this.dossierTemplateId = dossier.dossierTemplateId))); - this.currentDossier = this._dossiersService.find(this.dossierId); + this.dossier$ = this._dossiersService.getEntityChanged$(this.dossierId).pipe( + tap(dossier => { + this.dossierTemplateId = dossier.dossierTemplateId; + this.#currentDossier = this._dossiersService.find(this.dossierId); + }), + ); + this.#currentDossier = this._dossiersService.find(this.dossierId); this._updateFileAttributes(); + this.workflowConfig = this.configService.workflowConfig(this.#currentDossier); } get checkedRequiredFilters(): NestedFilter[] { @@ -121,7 +125,7 @@ export class DossierOverviewScreenComponent extends ListingComponent imple lastOpenedFn = (file: File) => this._userPreferenceService.getLastOpenedFileForDossier(file.dossierId) === file.id; async ngOnInit(): Promise { - this._loadEntitiesFromState(); + this._computeAllFilters(); this._setRemovableSubscriptions(); @@ -133,7 +137,7 @@ export class DossierOverviewScreenComponent extends ListingComponent imple ) .subscribe(); - if (this.currentDossier.isActive) { + if (this.#currentDossier.isActive) { this._fileDropOverlayService.initFileDropHandling(this.dossierId); } @@ -149,7 +153,7 @@ export class DossierOverviewScreenComponent extends ListingComponent imple .subscribe(); this.addSubscription = this._dossierTemplatesService - .getEntityChanged$(this.currentDossier.dossierTemplateId) + .getEntityChanged$(this.#currentDossier.dossierTemplateId) .pipe( skip(1), tap(() => { @@ -159,7 +163,7 @@ export class DossierOverviewScreenComponent extends ListingComponent imple .subscribe(); try { - this.dossierAttributes = await this._dossierAttributesService.getWithValues(this.currentDossier); + this.dossierAttributes = await this._dossierAttributesService.getWithValues(this.#currentDossier); } catch (e) { console.log('Error from dossier overview screen: ', e); } @@ -180,8 +184,7 @@ export class DossierOverviewScreenComponent extends ListingComponent imple @HostListener('drop', ['$event']) onDrop(event: DragEvent): void { - const currentDossier = this._dossiersService.find(this.dossierId); - handleFileDrop(event, currentDossier, this._uploadFiles.bind(this)); + handleFileDrop(event, this.#currentDossier, this._uploadFiles.bind(this)); } @HostListener('dragover', ['$event']) @@ -191,7 +194,7 @@ export class DossierOverviewScreenComponent extends ListingComponent imple } async uploadFiles(files: Files): Promise { - await this._uploadFiles(convertFiles(files, this.currentDossier)); + await this._uploadFiles(convertFiles(files, this.#currentDossier)); (this._fileInput as any).nativeElement.value = null; } @@ -210,18 +213,13 @@ export class DossierOverviewScreenComponent extends ListingComponent imple private _updateFileAttributes(): void { this._fileAttributeConfigs = - this._fileAttributesService.getFileAttributeConfig(this.currentDossier.dossierTemplateId)?.fileAttributeConfigs || []; + this._fileAttributesService.getFileAttributeConfig(this.#currentDossier.dossierTemplateId)?.fileAttributeConfigs || []; this.displayedInFileListAttributes = this._fileAttributeConfigs.filter(config => config.displayedInFileList); this.displayedAttributes = this.displayedInFileListAttributes.filter(c => c.displayedInFileList); this.tableColumnConfigs = this.configService.tableConfig(this.displayedAttributes); this._computeAllFilters(); } - private _loadEntitiesFromState() { - this.currentDossier = this._dossiersService.find(this.dossierId); - this._computeAllFilters(); - } - private async _uploadFiles(files: FileUploadModel[]) { const fileCount = await this._fileUploadService.uploadFiles(files, this.dossierId); if (fileCount) { 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 afc999a51..508e8d097 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 @@ -12,7 +12,7 @@ import { ViewChild, } from '@angular/core'; import { PermissionsService } from '@services/permissions.service'; -import { Action, ActionTypes, File } from '@red/domain'; +import { Action, ActionTypes, Dossier, File } from '@red/domain'; import { DossiersDialogService } from '../../../services/dossiers-dialog.service'; import { AutoUnsubscribe, @@ -42,7 +42,7 @@ import { RedactionImportService } from '../../services/redaction-import.service' import { PageRotationService } from '../../../../file-preview/services/page-rotation.service'; @Component({ - selector: 'redaction-file-actions [file] [type]', + selector: 'redaction-file-actions [file] [type] [dossier]', templateUrl: './file-actions.component.html', styleUrls: ['./file-actions.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush, @@ -52,6 +52,7 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy, readonly currentUser = this._userService.currentUser; @Input() file: File; + @Input() dossier: Dossier; @Input() type: 'file-preview' | 'dossier-overview-list' | 'dossier-overview-workflow'; @Input() maxWidth: number; @Input() fileActionsHelpModeKey: 'document_features' | 'editor_document_features' = 'document_features'; @@ -438,14 +439,14 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy, this.showSetToNew = this._permissionsService.canSetToNew(this.file) && !this.isDossierOverviewWorkflow; this.showUndoApproval = this._permissionsService.canUndoApproval(this.file) && !this.isDossierOverviewWorkflow; this.showUnderReview = this._permissionsService.canSetUnderReview(this.file) && !this.isDossierOverviewWorkflow; - this.showUnderApproval = this._permissionsService.canSetUnderApproval(this.file) && !this.isDossierOverviewWorkflow; + this.showUnderApproval = this._permissionsService.canSetUnderApproval(this.file, this.dossier) && !this.isDossierOverviewWorkflow; this.showApprove = this._permissionsService.isReadyForApproval(this.file) && !this.isDossierOverviewWorkflow; this.canToggleAnalysis = this._permissionsService.canToggleAnalysis(this.file); this.showToggleAnalysis = this._permissionsService.showToggleAnalysis(this.file); this.showDelete = this._permissionsService.canDeleteFile(this.file); this.showOCR = this._permissionsService.canOcrFile(this.file); - this.canReanalyse = this._permissionsService.canReanalyseFile(this.file); + this.canReanalyse = this._permissionsService.canReanalyseFile(this.file, this.dossier); this.canDisableAutoAnalysis = this._permissionsService.canDisableAutoAnalysis([this.file]); this.canEnableAutoAnalysis = this._permissionsService.canEnableAutoAnalysis([this.file]); diff --git a/apps/red-ui/src/app/modules/file-preview/components/annotation-details/annotation-details.component.ts b/apps/red-ui/src/app/modules/file-preview/components/annotation-details/annotation-details.component.ts index 7d01f50dc..594d0b0ee 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/annotation-details/annotation-details.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/components/annotation-details/annotation-details.component.ts @@ -4,6 +4,7 @@ import { TranslateService } from '@ngx-translate/core'; import { annotationChangesTranslations } from '../../../../translations/annotation-changes-translations'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { MultiSelectService } from '../../services/multi-select.service'; +import { KeysOf } from '@iqser/common-ui'; interface Engine { readonly icon: string; @@ -46,12 +47,13 @@ export class AnnotationDetailsComponent implements OnChanges { } private _updateChanges(): void { - const changesProperties = [ + const changesProperties: KeysOf[] = [ 'hasBeenResized', 'hasBeenRecategorized', 'hasLegalBasisChanged', - 'hasBeenForced', 'hasBeenRemovedByManualOverride', + 'hasBeenForcedRedaction', + 'hasBeenForcedHint', ]; const changes = changesProperties.filter(key => this.annotation[key]); const header = this._translateService.instant(_('annotation-changes.header')); diff --git a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.html b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.html index 8f1822104..5a078278f 100644 --- a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.html +++ b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.html @@ -19,6 +19,7 @@
this._canReanalyseFile(_file) && acc, true); + return files.reduce((acc, _file) => this._canReanalyseFile(_file, dossier) && acc, true); } canEnableAutoAnalysis(files: File[]): boolean { @@ -133,9 +132,9 @@ export class PermissionsService { return this.canSetUnderReview(files); } - canSetUnderApproval(file: File | File[]): boolean { + canSetUnderApproval(file: File | File[], dossier: Dossier): boolean { const files = file instanceof File ? [file] : file; - return files.reduce((acc, _file) => this._canSetUnderApproval(_file) && acc, true); + return files.reduce((acc, _file) => this._canSetUnderApproval(_file, dossier) && acc, true); } isOwner(dossier: Dossier, user = this._userService.currentUser): boolean { @@ -146,10 +145,6 @@ export class PermissionsService { return dossier.approverIds.indexOf(user.id) >= 0; } - isDossierReviewer(dossier: Dossier, user = this._userService.currentUser): boolean { - return this.isDossierMember(dossier, user) && !this.isApprover(dossier, user); - } - isDossierMember(dossier: Dossier, user = this._userService.currentUser): boolean { return dossier.memberIds.includes(user.id); } @@ -253,8 +248,8 @@ export class PermissionsService { ); } - private _canReanalyseFile(file: File): boolean { - return this._isActive(file) && this.isReviewerOrApprover(file) && file.analysisRequired; + private _canReanalyseFile(file: File, dossier: Dossier): boolean { + return this._isActive(file) && this.isReviewerOrApprover(file, dossier) && file.analysisRequired; } private _canEnableAutoAnalysis(file: File): boolean { @@ -281,8 +276,8 @@ export class PermissionsService { return precondition && (file.isNew || file.isUnderReview || (file.isUnderApproval && this.isApprover(dossier))); } - private _canSetUnderApproval(file: File): boolean { - return this._isActive(file) && file.isUnderReview && this.isReviewerOrApprover(file); + private _canSetUnderApproval(file: File, dossier: Dossier): boolean { + return this._isActive(file) && file.isUnderReview && this.isReviewerOrApprover(file, dossier); } private _canUndoApproval(file: File, dossier: Dossier): boolean { From 4fbe34f5a4ba9740b7aa95db01d352006c688400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Thu, 17 Mar 2022 01:16:14 +0200 Subject: [PATCH 2/4] Remove dossiersServiceResolver from PermissionsService [2] --- ...dossier-overview-bulk-actions.component.ts | 17 ++++++---- ...sier-overview-screen-header.component.html | 1 + .../dossier-overview/config.service.ts | 11 +++--- ...sign-reviewer-approver-dialog.component.ts | 2 +- .../file-actions/file-actions.component.ts | 16 +++++---- .../dossiers-listing-actions.component.html | 1 + .../document-info.component.html | 4 +-- .../user-management.component.ts | 6 ++-- .../file-download-btn.component.ts | 9 +++-- .../expandable-file-actions.component.html | 11 +++--- .../expandable-file-actions.component.ts | 2 +- .../services/entity-services/trash.service.ts | 8 ++--- .../src/app/services/permissions.service.ts | 34 +++++++------------ .../src/lib/shared/expandable-file-actions.ts | 2 ++ 14 files changed, 62 insertions(+), 62 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 dfa7e203b..47edcdc94 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 @@ -96,6 +96,7 @@ export class DossierOverviewBulkActionsComponent implements OnChanges { type: ActionTypes.downloadBtn, show: true, files: this.selectedFiles, + dossier: this.dossier, }, { type: ActionTypes.circleBtn, @@ -175,12 +176,14 @@ export class DossierOverviewBulkActionsComponent implements OnChanges { this.#canAssign = this.#canMoveToSameState && this.selectedFiles.reduce( - (acc, file) => (acc && this._permissionsService.canAssignUser(file)) || this._permissionsService.canUnassignUser(file), + (acc, file) => + (acc && this._permissionsService.canAssignUser(file, this.dossier)) || + this._permissionsService.canUnassignUser(file, this.dossier), true, ); - this.#canAssignToSelf = this.#canMoveToSameState && this._permissionsService.canAssignToSelf(this.selectedFiles); + this.#canAssignToSelf = this.#canMoveToSameState && this._permissionsService.canAssignToSelf(this.selectedFiles, this.dossier); - this.#canDelete = this._permissionsService.canDeleteFile(this.selectedFiles); + this.#canDelete = this._permissionsService.canDeleteFile(this.selectedFiles, this.dossier); this.#canReanalyse = this._permissionsService.canReanalyseFile(this.selectedFiles, this.dossier); @@ -190,19 +193,19 @@ export class DossierOverviewBulkActionsComponent implements OnChanges { this.#canToggleAnalysis = this._permissionsService.canToggleAnalysis(this.selectedFiles); - this.#canOcr = this._permissionsService.canOcrFile(this.selectedFiles); + this.#canOcr = this._permissionsService.canOcrFile(this.selectedFiles, this.dossier); this.#canSetToNew = this._permissionsService.canSetToNew(this.selectedFiles) && !isWorkflow; - this.#canSetToUnderReview = this._permissionsService.canSetUnderReview(this.selectedFiles) && !isWorkflow; + this.#canSetToUnderReview = this._permissionsService.canSetUnderReview(this.selectedFiles, this.dossier) && !isWorkflow; this.#canSetToUnderApproval = this._permissionsService.canSetUnderApproval(this.selectedFiles, this.dossier) && !isWorkflow; - this.#isReadyForApproval = this._permissionsService.isReadyForApproval(this.selectedFiles) && !isWorkflow; + this.#isReadyForApproval = this._permissionsService.isReadyForApproval(this.selectedFiles, this.dossier) && !isWorkflow; this.#canApprove = this._permissionsService.canBeApproved(this.selectedFiles) && !isWorkflow; - this.#canUndoApproval = this._permissionsService.canUndoApproval(this.selectedFiles) && !isWorkflow; + this.#canUndoApproval = this._permissionsService.canUndoApproval(this.selectedFiles, this.dossier) && !isWorkflow; this.#assignTooltip = allFilesAreUnderApproval ? _('dossier-overview.assign-approver') : _('dossier-overview.assign-reviewer'); diff --git a/apps/red-ui/src/app/modules/dossier-overview/components/screen-header/dossier-overview-screen-header.component.html b/apps/red-ui/src/app/modules/dossier-overview/components/screen-header/dossier-overview-screen-header.component.html index 2edb909ac..15b9a88a0 100644 --- a/apps/red-ui/src/app/modules/dossier-overview/components/screen-header/dossier-overview-screen-header.component.html +++ b/apps/red-ui/src/app/modules/dossier-overview/components/screen-header/dossier-overview-screen-header.component.html @@ -7,6 +7,7 @@ > - this._permissionsService.canSetUnderReview(files) || - this._permissionsService.canAssignToSelf(files) || - this._permissionsService.canAssignUser(files), + this._permissionsService.canSetUnderReview(files, dossier) || + this._permissionsService.canAssignToSelf(files, dossier) || + this._permissionsService.canAssignUser(files, dossier), key: WorkflowFileStatuses.UNDER_REVIEW, color: '#FDBD00', entities: new BehaviorSubject([]), @@ -83,7 +83,8 @@ export class ConfigService { label: workflowFileStatusTranslations[WorkflowFileStatuses.UNDER_APPROVAL], enterFn: (files: File[]) => this._bulkActionsService.setToUnderApproval(files), enterPredicate: (files: File[]) => - this._permissionsService.canSetUnderApproval(files, dossier) || this._permissionsService.canUndoApproval(files), + this._permissionsService.canSetUnderApproval(files, dossier) || + this._permissionsService.canUndoApproval(files, dossier), key: WorkflowFileStatuses.UNDER_APPROVAL, color: '#374C81', entities: new BehaviorSubject([]), @@ -92,7 +93,7 @@ export class ConfigService { label: workflowFileStatusTranslations[WorkflowFileStatuses.APPROVED], enterFn: (files: File[]) => this._bulkActionsService.approve(files), enterPredicate: (files: File[]) => - this._permissionsService.isReadyForApproval(files) && this._permissionsService.canBeApproved(files), + this._permissionsService.isReadyForApproval(files, dossier) && this._permissionsService.canBeApproved(files), key: WorkflowFileStatuses.APPROVED, color: '#48C9F7', entities: new BehaviorSubject([]), diff --git a/apps/red-ui/src/app/modules/dossier/dialogs/assign-reviewer-approver-dialog/assign-reviewer-approver-dialog.component.ts b/apps/red-ui/src/app/modules/dossier/dialogs/assign-reviewer-approver-dialog/assign-reviewer-approver-dialog.component.ts index b1f7e77b4..2f7bc49bb 100644 --- a/apps/red-ui/src/app/modules/dossier/dialogs/assign-reviewer-approver-dialog/assign-reviewer-approver-dialog.component.ts +++ b/apps/red-ui/src/app/modules/dossier/dialogs/assign-reviewer-approver-dialog/assign-reviewer-approver-dialog.component.ts @@ -67,7 +67,7 @@ export class AssignReviewerApproverDialogComponent { } private get _canUnassignFiles() { - return this.permissionsService.canUnassignUser(this.data.files); + return this.permissionsService.canUnassignUser(this.data.files, this.dossier); } /** Initialize the form with: 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 508e8d097..4374b7c81 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 @@ -162,6 +162,7 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy, type: ActionTypes.downloadBtn, show: true, files: [this.file], + dossier: this.dossier, tooltipClass: 'small', }, { @@ -437,24 +438,25 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy, this.toggleTooltip = this._toggleTooltip; this.showSetToNew = this._permissionsService.canSetToNew(this.file) && !this.isDossierOverviewWorkflow; - this.showUndoApproval = this._permissionsService.canUndoApproval(this.file) && !this.isDossierOverviewWorkflow; - this.showUnderReview = this._permissionsService.canSetUnderReview(this.file) && !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.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.showDelete = this._permissionsService.canDeleteFile(this.file); - this.showOCR = this._permissionsService.canOcrFile(this.file); + 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.showStatusBar = !this.file.isError && !this.file.isUnprocessed && this.isDossierOverviewList; - this.showAssignToSelf = this._permissionsService.canAssignToSelf(this.file) && this.isDossierOverview; + this.showAssignToSelf = this._permissionsService.canAssignToSelf(this.file, this.dossier) && this.isDossierOverview; this.showAssign = - (this._permissionsService.canAssignUser(this.file) || this._permissionsService.canUnassignUser(this.file)) && + (this._permissionsService.canAssignUser(this.file, this.dossier) || + this._permissionsService.canUnassignUser(this.file, this.dossier)) && this.isDossierOverview; this.showImportRedactions = this._permissionsService.canImportRedactions(this.file); diff --git a/apps/red-ui/src/app/modules/dossiers-listing/components/dossiers-listing-actions/dossiers-listing-actions.component.html b/apps/red-ui/src/app/modules/dossiers-listing/components/dossiers-listing-actions/dossiers-listing-actions.component.html index b58f96883..8e84ed10d 100644 --- a/apps/red-ui/src/app/modules/dossiers-listing/components/dossiers-listing-actions/dossiers-listing-actions.component.html +++ b/apps/red-ui/src/app/modules/dossiers-listing/components/dossiers-listing-actions/dossiers-listing-actions.component.html @@ -18,6 +18,7 @@ >
-
+
this.permissionsService.canAssignToSelf(file)), + map(([file, dossier]) => this.permissionsService.canAssignToSelf(file, dossier)), distinctUntilChanged(), ); this._canAssignUser$ = this.stateService.file$.pipe( combineLatestWith(this.stateService.dossier$), - map(([file]) => this.permissionsService.canAssignUser(file)), + map(([file, dossier]) => this.permissionsService.canAssignUser(file, dossier)), distinctUntilChanged(), ); this._canUnassignUser$ = this.stateService.file$.pipe( combineLatestWith(this.stateService.dossier$), - map(([file]) => this.permissionsService.canUnassignUser(file)), + map(([file, dossier]) => this.permissionsService.canUnassignUser(file, dossier)), distinctUntilChanged(), ); diff --git a/apps/red-ui/src/app/modules/shared/components/buttons/file-download-btn/file-download-btn.component.ts b/apps/red-ui/src/app/modules/shared/components/buttons/file-download-btn/file-download-btn.component.ts index 0b595cdf7..66912c469 100644 --- a/apps/red-ui/src/app/modules/shared/components/buttons/file-download-btn/file-download-btn.component.ts +++ b/apps/red-ui/src/app/modules/shared/components/buttons/file-download-btn/file-download-btn.component.ts @@ -1,21 +1,20 @@ import { ChangeDetectionStrategy, Component, Input, OnChanges } from '@angular/core'; import { PermissionsService } from '@services/permissions.service'; -import { File } from '@red/domain'; +import { Dossier, File } from '@red/domain'; import { FileDownloadService } from '@upload-download/services/file-download.service'; import { CircleButtonType, CircleButtonTypes, Toaster } from '@iqser/common-ui'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { firstValueFrom } from 'rxjs'; -export type MenuState = 'OPEN' | 'CLOSED'; - @Component({ - selector: 'redaction-file-download-btn', + selector: 'redaction-file-download-btn [files] [dossier]', templateUrl: './file-download-btn.component.html', styleUrls: ['./file-download-btn.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush, }) export class FileDownloadBtnComponent implements OnChanges { @Input() files: File[]; + @Input() dossier: Dossier; @Input() tooltipPosition: 'above' | 'below' | 'before' | 'after' = 'above'; @Input() type: CircleButtonType = CircleButtonTypes.default; @Input() tooltipClass: string; @@ -31,7 +30,7 @@ export class FileDownloadBtnComponent implements OnChanges { ) {} ngOnChanges(): void { - this.canDownloadFiles = this._permissionsService.canDownloadFiles(this.files); + this.canDownloadFiles = this._permissionsService.canDownloadFiles(this.files, this.dossier); this.tooltip = this.canDownloadFiles ? _('dossier-overview.download-file') : _('dossier-overview.download-file-disabled'); } diff --git a/apps/red-ui/src/app/modules/shared/components/expandable-file-actions/expandable-file-actions.component.html b/apps/red-ui/src/app/modules/shared/components/expandable-file-actions/expandable-file-actions.component.html index 2a838dfbf..3ad717745 100644 --- a/apps/red-ui/src/app/modules/shared/components/expandable-file-actions/expandable-file-actions.component.html +++ b/apps/red-ui/src/app/modules/shared/components/expandable-file-actions/expandable-file-actions.component.html @@ -5,24 +5,25 @@ [attr.aria-expanded]="btn.ariaExpanded && btn.ariaExpanded | async" [disabled]="btn.disabled" [icon]="btn.icon" + [iqserHelpMode]="helpModeKey" + [scrollableParentView]="scrollableParentView" [showDot]="btn.showDot" [tooltipClass]="btn.tooltipClass" [tooltipPosition]="tooltipPosition" [tooltip]="btn.tooltip | translate" [type]="btn.buttonType || buttonType" - [iqserHelpMode]="helpModeKey" - [scrollableParentView]="scrollableParentView" > @@ -32,10 +33,10 @@ (click)="$event.stopPropagation()" [checked]="btn.checked" [disabled]="btn.disabled" + [iqserHelpMode]="helpModeKey" [matTooltipPosition]="tooltipPosition" [matTooltip]="btn.tooltip | translate" [ngClass]="btn.class" - [iqserHelpMode]="helpModeKey" [scrollableParentView]="scrollableParentView" color="primary" > diff --git a/apps/red-ui/src/app/modules/shared/components/expandable-file-actions/expandable-file-actions.component.ts b/apps/red-ui/src/app/modules/shared/components/expandable-file-actions/expandable-file-actions.component.ts index c3cf688a2..9e59249c4 100644 --- a/apps/red-ui/src/app/modules/shared/components/expandable-file-actions/expandable-file-actions.component.ts +++ b/apps/red-ui/src/app/modules/shared/components/expandable-file-actions/expandable-file-actions.component.ts @@ -55,7 +55,7 @@ export class ExpandableFileActionsComponent implements OnChanges { const downloadBtn = this.actions.find(btn => btn.type === ActionTypes.downloadBtn); if (downloadBtn) { downloadBtn.action = ($event: MouseEvent) => this._downloadFiles($event, downloadBtn.files); - downloadBtn.disabled = !this._permissionsService.canDownloadFiles(downloadBtn.files); + downloadBtn.disabled = !this._permissionsService.canDownloadFiles(downloadBtn.files, downloadBtn.dossier); } } } diff --git a/apps/red-ui/src/app/services/entity-services/trash.service.ts b/apps/red-ui/src/app/services/entity-services/trash.service.ts index b8dc6ad17..278a26fef 100644 --- a/apps/red-ui/src/app/services/entity-services/trash.service.ts +++ b/apps/red-ui/src/app/services/entity-services/trash.service.ts @@ -73,7 +73,7 @@ export class TrashService extends GenericService { this._permissionsService.canDeleteDossier(dossier), ), ), - switchMap(dossiers => this._dossierStatsService.getFor(dossiers.map(d => d.id) as string[]).pipe(map(() => dossiers))), + switchMap(dossiers => this._dossierStatsService.getFor(dossiers.map(d => d.id)).pipe(map(() => dossiers))), ); } @@ -82,12 +82,12 @@ export class TrashService extends GenericService { map(res => flatMap(Object.values(res))), mapEach(file => new File(file, this._userService.getNameForId(file.assignee), this._activeDossiersService.routerPath)), mapEach(file => { - const dossierTemplateId = this._activeDossiersService.find(file.dossierId).dossierTemplateId; + const dossier = this._activeDossiersService.find(file.dossierId); return new TrashFile( file, - dossierTemplateId, + dossier.dossierTemplateId, this._configService.values.DELETE_RETENTION_HOURS as number, - this._permissionsService.canDeleteFile(file), + this._permissionsService.canDeleteFile(file, dossier), ); }), ); diff --git a/apps/red-ui/src/app/services/permissions.service.ts b/apps/red-ui/src/app/services/permissions.service.ts index 95c65130c..a113be62a 100644 --- a/apps/red-ui/src/app/services/permissions.service.ts +++ b/apps/red-ui/src/app/services/permissions.service.ts @@ -42,8 +42,7 @@ export class PermissionsService { return dossier.isActive; } - canEditFileAttributes(file: File): boolean { - const dossier = this._getDossier(file); + canEditFileAttributes(file: File, dossier: Dossier): boolean { return ( this._isActive(file) && (((file.isUnderReview || file.isNew) && this.isDossierMember(dossier)) || (file.isUnderApproval && this.isApprover(dossier))) @@ -78,9 +77,8 @@ export class PermissionsService { return file.assignee === this._userService.currentUser.id; } - canDeleteFile(file: File | File[]): boolean { + canDeleteFile(file: File | File[], dossier: Dossier): boolean { const files = file instanceof File ? [file] : file; - const dossier = this._getDossier(files[0]); return files.reduce((acc, _file) => this._canDeleteFile(_file, dossier) && acc, true); } @@ -88,27 +86,23 @@ export class PermissionsService { return dossier.isActive; } - canOcrFile(file: File | File[]): boolean { + canOcrFile(file: File | File[], dossier: Dossier): boolean { const files = file instanceof File ? [file] : file; - const dossier = this._getDossier(files[0]); return files.reduce((acc, _file) => this._canOcrFile(_file, dossier) && acc, true); } - canAssignToSelf(file: File | File[]): boolean { + canAssignToSelf(file: File | File[], dossier: Dossier): boolean { const files = file instanceof File ? [file] : file; - const dossier = this._getDossier(files[0]); return files.reduce((acc, _file) => this._canAssignToSelf(_file, dossier) && acc, true); } - canAssignUser(file: File | File[]): boolean { + canAssignUser(file: File | File[], dossier: Dossier): boolean { const files = file instanceof File ? [file] : file; - const dossier = this._getDossier(files[0]); return files.reduce((acc, _file) => this._canAssignUser(_file, dossier) && acc, true); } - canUnassignUser(file: File | File[]): boolean { + canUnassignUser(file: File | File[], dossier: Dossier): boolean { const files = file instanceof File ? [file] : file; - const dossier = this._getDossier(files[0]); return files.reduce((acc, _file) => this._canUnassignUser(_file, dossier) && acc, true); } @@ -117,9 +111,8 @@ export class PermissionsService { return files.reduce((acc, _file) => this._canSetToNew(_file) && acc, true); } - canSetUnderReview(file: File | File[]): boolean { + canSetUnderReview(file: File | File[], dossier: Dossier): boolean { const files = file instanceof File ? [file] : file; - const dossier = this._getDossier(files[0]); return this.isApprover(dossier) && files.reduce((acc, _file) => this._canSetUnderReview(_file) && acc, true); } @@ -128,8 +121,8 @@ export class PermissionsService { return files.reduce((acc, _file) => this._canBeApproved(_file) && acc, true); } - isReadyForApproval(files: File | File[]): boolean { - return this.canSetUnderReview(files); + isReadyForApproval(files: File | File[], dossier: Dossier): boolean { + return this.canSetUnderReview(files, dossier); } canSetUnderApproval(file: File | File[], dossier: Dossier): boolean { @@ -149,20 +142,18 @@ export class PermissionsService { return dossier.memberIds.includes(user.id); } - // TODO: Remove '?', after we make sure file is loaded before page canPerformAnnotationActions(file: File): boolean { return ( this._isActive(file) && !file.isOcrProcessing && !file.excluded && - (file?.isUnderReview || file?.isUnderApproval) && + (file.isUnderReview || file.isUnderApproval) && this.isFileAssignee(file) ); } - canUndoApproval(file: File | File[]): boolean { + canUndoApproval(file: File | File[], dossier: Dossier): boolean { const files = file instanceof File ? [file] : file; - const dossier = this._getDossier(files[0]); return files.reduce((acc, _file) => this._canUndoApproval(_file, dossier) && acc, true); } @@ -170,11 +161,10 @@ export class PermissionsService { return (file.isUnderReview || file.isUnderApproval) && this.isFileAssignee(file); } - canDownloadFiles(files: File[]): boolean { + canDownloadFiles(files: File[], dossier: Dossier): boolean { if (files.length === 0) { return false; } - const dossier = this._getDossier(files[0]); return this.isApprover(dossier) && files.reduce((prev, file) => prev && file.isApproved, true); } diff --git a/libs/red-domain/src/lib/shared/expandable-file-actions.ts b/libs/red-domain/src/lib/shared/expandable-file-actions.ts index 3fd17d5e8..c599d9fef 100644 --- a/libs/red-domain/src/lib/shared/expandable-file-actions.ts +++ b/libs/red-domain/src/lib/shared/expandable-file-actions.ts @@ -1,6 +1,7 @@ import { Observable } from 'rxjs'; import { CircleButtonType } from '@iqser/common-ui'; import { File } from '../files'; +import { Dossier } from '../dossiers'; export type ActionType = 'circleBtn' | 'downloadBtn' | 'toggle'; @@ -23,6 +24,7 @@ export interface Action { checked?: boolean; class?: { [key: string]: boolean }; files?: File[]; + dossier?: Dossier; type: ActionType; readonly helpModeKey?: string; } 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 3/4] 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; } } From 8b9dd584d8ed9596f299a30250def8e9864fc9c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Thu, 17 Mar 2022 01:34:36 +0200 Subject: [PATCH 4/4] Remove dossiers service getter from file preview state service --- .../services/file-preview-state.service.ts | 11 ++++------- .../entity-services/dossiers.service.provider.ts | 2 ++ 2 files changed, 6 insertions(+), 7 deletions(-) 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 683bc06a9..bd3b5846f 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 @@ -8,7 +8,6 @@ import { boolFactory } from '@iqser/common-ui'; import { filter, startWith } from 'rxjs/operators'; import { FileManagementService } from '@services/entity-services/file-management.service'; import { DOSSIER_ID, FILE_ID } from '@utils/constants'; -import { DossiersService } from '@services/dossiers/dossiers.service'; import { dossiersServiceResolver } from '@services/entity-services/dossiers.service.provider'; import { wipeFilesCache } from '@red/cache'; @@ -31,11 +30,13 @@ export class FilePreviewStateService { private readonly _filesMapService: FilesMapService, private readonly _permissionsService: PermissionsService, ) { + const dossiersService = dossiersServiceResolver(this._injector); + this.fileId = _route.snapshot.paramMap.get(FILE_ID); this.dossierId = _route.snapshot.paramMap.get(DOSSIER_ID); - this.dossierTemplateId = this._dossiersService.find(this.dossierId).dossierTemplateId; + this.dossierTemplateId = dossiersService.find(this.dossierId).dossierTemplateId; - this.dossier$ = this._dossiersService.getEntityChanged$(this.dossierId); + this.dossier$ = dossiersService.getEntityChanged$(this.dossierId); this.file$ = _filesMapService.watch$(this.dossierId, this.fileId); [this.isReadonly$, this.isWritable$] = boolFactory( combineLatest([this.file$, this.dossier$]), @@ -57,10 +58,6 @@ export class FilePreviewStateService { return firstValueFrom(this.blob$); } - private get _dossiersService(): DossiersService { - return dossiersServiceResolver(this._injector); - } - get #blob$() { return this.file$.pipe( startWith(undefined), diff --git a/apps/red-ui/src/app/services/entity-services/dossiers.service.provider.ts b/apps/red-ui/src/app/services/entity-services/dossiers.service.provider.ts index 0acf1c071..42b0de04a 100644 --- a/apps/red-ui/src/app/services/entity-services/dossiers.service.provider.ts +++ b/apps/red-ui/src/app/services/entity-services/dossiers.service.provider.ts @@ -2,6 +2,8 @@ import { ActivatedRoute } from '@angular/router'; import { Injector, ProviderToken } from '@angular/core'; import { DossiersService } from '../dossiers/dossiers.service'; +/** Usage in components or services is only allowed in guards or in constructors. + * Otherwise, it causes errors on navigation to other screens if the component is reused. */ export const dossiersServiceResolver = (injector: Injector) => { let route: ActivatedRoute = injector.get(ActivatedRoute); while (route.firstChild) {