Remove dossiersServiceResolver from PermissionsService [3]

This commit is contained in:
Adina Țeudan 2022-03-17 01:29:46 +02:00
parent 4fbe34f5a4
commit d3c297e29d
9 changed files with 98 additions and 108 deletions

View File

@ -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;

View File

@ -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([]),

View File

@ -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;

View File

@ -1,34 +1,36 @@
<ng-container *ngIf="file$ | async as file">
<div *ngFor="let comment of annotation.comments; trackBy: trackBy" class="comment">
<div class="comment-details-wrapper">
<div [matTooltipPosition]="'above'" [matTooltip]="comment.date | date: 'exactDate'" class="small-label">
<strong> {{ comment.user | name }} </strong>
{{ comment.date | date: 'sophisticatedDate' }}
<ng-container *ngIf="dossier$ | async as dossier">
<div *ngFor="let comment of annotation.comments; trackBy: trackBy" class="comment">
<div class="comment-details-wrapper">
<div [matTooltipPosition]="'above'" [matTooltip]="comment.date | date: 'exactDate'" class="small-label">
<strong> {{ comment.user | name }} </strong>
{{ comment.date | date: 'sophisticatedDate' }}
</div>
<div class="comment-actions">
<iqser-circle-button
(action)="deleteComment($event, comment)"
*ngIf="permissionsService.canDeleteComment(comment, file, dossier)"
[iconSize]="10"
[size]="20"
class="pointer"
icon="iqser:trash"
></iqser-circle-button>
</div>
</div>
<div class="comment-actions">
<iqser-circle-button
(action)="deleteComment($event, comment)"
*ngIf="permissionsService.canDeleteComment(comment, file)"
[iconSize]="10"
[size]="20"
class="pointer"
icon="iqser:trash"
></iqser-circle-button>
</div>
<div>{{ comment.text }}</div>
</div>
<div>{{ comment.text }}</div>
</div>
<iqser-input-with-action
(action)="addComment($event)"
*ngIf="permissionsService.canAddComment(file)"
[placeholder]="'comments.add-comment' | translate"
autocomplete="off"
icon="iqser:collapse"
width="full"
></iqser-input-with-action>
<iqser-input-with-action
(action)="addComment($event)"
*ngIf="permissionsService.canAddComment(file, dossier)"
[placeholder]="'comments.add-comment' | translate"
autocomplete="off"
icon="iqser:collapse"
width="full"
></iqser-input-with-action>
</ng-container>
</ng-container>
<div (click)="toggleExpandComments($event)" class="all-caps-label pointer hide-comments" translate="comments.hide-comments"></div>

View File

@ -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<File>;
readonly dossier$: Observable<Dossier>;
@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() {

View File

@ -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$;

View File

@ -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(),
);
}

View File

@ -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$;
}

View File

@ -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;
}
}