Remove dossiersServiceResolver from PermissionsService [1]

This commit is contained in:
Adina Țeudan 2022-03-17 00:41:55 +02:00
parent cb0e890a7d
commit 9692f449b7
12 changed files with 66 additions and 56 deletions

View File

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

View File

@ -56,5 +56,11 @@
></iqser-status-bar>
</div>
<redaction-file-actions *ngIf="!file.isProcessing" [file]="file" class="mr-4" type="dossier-overview-list"></redaction-file-actions>
<redaction-file-actions
*ngIf="!file.isProcessing"
[dossier]="dossier"
[file]="file"
class="mr-4"
type="dossier-overview-list"
></redaction-file-actions>
</div>

View File

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

View File

@ -25,6 +25,7 @@
<div #actionsWrapper class="actions-wrapper">
<redaction-file-actions
*ngIf="!file.isProcessing"
[dossier]="dossier"
[file]="file"
[maxWidth]="width"
type="dossier-overview-workflow"

View File

@ -1,16 +1,17 @@
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core';
import { File, IFileAttributeConfig } from '@red/domain';
import { Debounce, Required } from '@iqser/common-ui';
import { Dossier, File, IFileAttributeConfig } from '@red/domain';
import { Debounce } from '@iqser/common-ui';
@Component({
selector: 'redaction-workflow-item',
selector: 'redaction-workflow-item [file] [dossier] [displayedAttributes]',
templateUrl: './workflow-item.component.html',
styleUrls: ['./workflow-item.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class WorkflowItemComponent implements OnInit {
@Input() @Required() file!: File;
@Input() @Required() displayedAttributes!: IFileAttributeConfig[];
@Input() file: File;
@Input() dossier: Dossier;
@Input() displayedAttributes: IFileAttributeConfig[];
width: number;
@ViewChild('actionsWrapper', { static: true }) private _actionsWrapper: ElementRef;

View File

@ -11,7 +11,7 @@ import {
TableColumnConfig,
WorkflowConfig,
} from '@iqser/common-ui';
import { File, IFileAttributeConfig, StatusSorter, WorkflowFileStatus, WorkflowFileStatuses } from '@red/domain';
import { Dossier, File, IFileAttributeConfig, StatusSorter, WorkflowFileStatus, WorkflowFileStatuses } from '@red/domain';
import { workflowFileStatusTranslations } from '../../translations/file-status-translations';
import { PermissionsService } from '@services/permissions.service';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
@ -49,7 +49,7 @@ export class ConfigService {
this._listingMode$.next(listingMode);
}
get workflowConfig(): WorkflowConfig<File, WorkflowFileStatus> {
workflowConfig(dossier: Dossier): WorkflowConfig<File, WorkflowFileStatus> {
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([]),

View File

@ -67,6 +67,7 @@
<redaction-table-item
[displayedAttributes]="displayedAttributes"
[dossierTemplateId]="dossier.dossierTemplateId"
[dossier]="dossier"
[file]="file"
></redaction-table-item>
</ng-template>
@ -79,5 +80,9 @@
<input #fileInput (change)="uploadFiles($event.target['files'])" class="file-upload-input" multiple="true" type="file" />
<ng-template #workflowItemTemplate let-entity="entity">
<redaction-workflow-item [displayedAttributes]="displayedAttributes" [file]="entity"></redaction-workflow-item>
<redaction-workflow-item
[displayedAttributes]="displayedAttributes"
[dossier]="dossier$ | async"
[file]="entity"
></redaction-workflow-item>
</ng-template>

View File

@ -69,11 +69,11 @@ export class DossierOverviewScreenComponent extends ListingComponent<File> imple
tableColumnConfigs: readonly TableColumnConfig<File>[];
displayedInFileListAttributes: IFileAttributeConfig[] = [];
displayedAttributes: IFileAttributeConfig[] = [];
readonly workflowConfig: WorkflowConfig<File, WorkflowFileStatus> = this.configService.workflowConfig;
readonly workflowConfig: WorkflowConfig<File, WorkflowFileStatus>;
readonly dossier$: Observable<Dossier>;
readonly dossierId: string;
currentDossier: Dossier;
dossierTemplateId: string;
#currentDossier: Dossier;
@ViewChild('needsWorkFilterTemplate', { read: TemplateRef, static: true })
private readonly _needsWorkFilterTemplate: TemplateRef<unknown>;
@ViewChild('fileInput', { static: true }) private readonly _fileInput: ElementRef;
@ -101,11 +101,15 @@ export class DossierOverviewScreenComponent extends ListingComponent<File> 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<File> imple
lastOpenedFn = (file: File) => this._userPreferenceService.getLastOpenedFileForDossier(file.dossierId) === file.id;
async ngOnInit(): Promise<void> {
this._loadEntitiesFromState();
this._computeAllFilters();
this._setRemovableSubscriptions();
@ -133,7 +137,7 @@ export class DossierOverviewScreenComponent extends ListingComponent<File> imple
)
.subscribe();
if (this.currentDossier.isActive) {
if (this.#currentDossier.isActive) {
this._fileDropOverlayService.initFileDropHandling(this.dossierId);
}
@ -149,7 +153,7 @@ export class DossierOverviewScreenComponent extends ListingComponent<File> 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<File> 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<File> 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<File> imple
}
async uploadFiles(files: Files): Promise<void> {
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<File> 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) {

View File

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

View File

@ -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<AnnotationWrapper>[] = [
'hasBeenResized',
'hasBeenRecategorized',
'hasLegalBasisChanged',
'hasBeenForced',
'hasBeenRemovedByManualOverride',
'hasBeenForcedRedaction',
'hasBeenForcedHint',
];
const changes = changesProperties.filter(key => this.annotation[key]);
const header = this._translateService.instant(_('annotation-changes.header'));

View File

@ -19,6 +19,7 @@
<div class="vertical-line"></div>
<redaction-file-actions
[dossier]="dossier"
[file]="file"
fileActionsHelpModeKey="editor_document_features"
type="file-preview"

View File

@ -26,8 +26,7 @@ export class PermissionsService {
return user.isAdmin;
}
isReviewerOrApprover(file: File): boolean {
const dossier = this._getDossier(file);
isReviewerOrApprover(file: File, dossier: Dossier): boolean {
return this.isFileAssignee(file) || this.isApprover(dossier);
}
@ -62,9 +61,9 @@ export class PermissionsService {
return this._isActive(files[0]);
}
canReanalyseFile(file: File | File[]): boolean {
canReanalyseFile(file: File | File[], dossier: Dossier): boolean {
const files = file instanceof File ? [file] : file;
return files.reduce((acc, _file) => 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 {