Update file permissions on dossier members change, assign to self permission fix
This commit is contained in:
parent
3170042ed2
commit
6e73430c97
@ -1,7 +1,6 @@
|
||||
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, OnDestroy, Optional, Output } from '@angular/core';
|
||||
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Optional, Output } from '@angular/core';
|
||||
import { PermissionsService } from '@services/permissions.service';
|
||||
import { File } from '@red/domain';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { DossiersDialogService } from '../../../services/dossiers-dialog.service';
|
||||
import {
|
||||
AutoUnsubscribe,
|
||||
@ -24,6 +23,7 @@ import { FilesService } from '@services/entity-services/files.service';
|
||||
import { ReanalysisService } from '@services/reanalysis.service';
|
||||
import { Router } from '@angular/router';
|
||||
import { ExcludedPagesService } from '../../../screens/file-preview-screen/services/excluded-pages.service';
|
||||
import { tap } from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
selector: 'redaction-file-actions',
|
||||
@ -31,7 +31,7 @@ import { ExcludedPagesService } from '../../../screens/file-preview-screen/servi
|
||||
styleUrls: ['./file-actions.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy, OnChanges {
|
||||
export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy, OnInit, OnChanges {
|
||||
readonly circleButtonTypes = CircleButtonTypes;
|
||||
readonly currentUser = this._userService.currentUser;
|
||||
|
||||
@ -67,10 +67,9 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy,
|
||||
@Output() readonly toggleViewDocumentInfo = new EventEmitter<void>();
|
||||
|
||||
constructor(
|
||||
readonly permissionsService: PermissionsService,
|
||||
readonly appStateService: AppStateService,
|
||||
readonly dossiersService: DossiersService,
|
||||
@Optional() readonly excludedPagesService: ExcludedPagesService,
|
||||
private readonly _permissionsService: PermissionsService,
|
||||
private readonly _dossiersService: DossiersService,
|
||||
private readonly _dialogService: DossiersDialogService,
|
||||
private readonly _fileAssignService: FileAssignService,
|
||||
private readonly _loadingService: LoadingService,
|
||||
@ -93,8 +92,12 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy,
|
||||
return this.file?.excluded ? _('file-preview.toggle-analysis.enable') : _('file-preview.toggle-analysis.disable');
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this._dossiersService.getEntityChanged$(this.file.dossierId).pipe(tap(() => this._setup()));
|
||||
}
|
||||
|
||||
ngOnChanges() {
|
||||
this.setup();
|
||||
this._setup();
|
||||
}
|
||||
|
||||
openDocument() {
|
||||
@ -112,7 +115,7 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy,
|
||||
async () => {
|
||||
this._loadingService.start();
|
||||
try {
|
||||
const dossier = this.dossiersService.find(this.file.dossierId);
|
||||
const dossier = this._dossiersService.find(this.file.dossierId);
|
||||
await this._fileManagementService.delete([this.file.fileId], this.file.dossierId).toPromise();
|
||||
await this._router.navigate([dossier.routerLink]);
|
||||
} catch (error) {
|
||||
@ -190,7 +193,7 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy,
|
||||
this.analysisForced = !$event.touchEnd && this._userPreferenceService.areDevFeaturesEnabled;
|
||||
}
|
||||
|
||||
setup() {
|
||||
private _setup() {
|
||||
this.isDossierOverviewList = this.type === 'dossier-overview-list';
|
||||
this.isDossierOverviewWorkflow = this.type === 'dossier-overview-workflow';
|
||||
this.isDossierOverview = this.type.startsWith('dossier-overview');
|
||||
@ -202,21 +205,22 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy,
|
||||
this.buttonType = this.isFilePreview ? CircleButtonTypes.default : CircleButtonTypes.dark;
|
||||
this.toggleTooltip = this._toggleTooltip;
|
||||
|
||||
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.showApprove = this.permissionsService.isReadyForApproval(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.showApprove = this._permissionsService.isReadyForApproval(this.file) && !this.isDossierOverviewWorkflow;
|
||||
|
||||
this.canToggleAnalysis = this.permissionsService.canToggleAnalysis(this.file);
|
||||
this.showDelete = this.permissionsService.canDeleteFile(this.file);
|
||||
this.canToggleAnalysis = this._permissionsService.canToggleAnalysis(this.file);
|
||||
this.showDelete = this._permissionsService.canDeleteFile(this.file);
|
||||
this.showOCR = this.file.canBeOCRed;
|
||||
this.canReanalyse = this.permissionsService.canReanalyseFile(this.file);
|
||||
this.canReanalyse = this._permissionsService.canReanalyseFile(this.file);
|
||||
|
||||
this.showStatusBar = !this.file.isError && !this.file.isPending && this.isDossierOverviewList;
|
||||
|
||||
this.showAssignToSelf = this.permissionsService.canAssignToSelf(this.file) && this.isDossierOverview;
|
||||
this.showAssignToSelf = this._permissionsService.canAssignToSelf(this.file) && this.isDossierOverview;
|
||||
console.log(this.showAssignToSelf);
|
||||
this.showAssign =
|
||||
(this.permissionsService.canAssignUser(this.file) || this.permissionsService.canUnassignUser(this.file)) &&
|
||||
(this._permissionsService.canAssignUser(this.file) || this._permissionsService.canUnassignUser(this.file)) &&
|
||||
this.isDossierOverview;
|
||||
|
||||
this.showOpenDocument = this.file.canBeOpened && this.isDossierOverviewWorkflow;
|
||||
|
||||
@ -11,7 +11,7 @@ export class PermissionsService {
|
||||
|
||||
isReviewerOrApprover(file: File): boolean {
|
||||
const dossier = this._getDossier(file);
|
||||
return this.isFileReviewer(file) || this.isApprover(dossier);
|
||||
return this.isFileAssignee(file) || this.isApprover(dossier);
|
||||
}
|
||||
|
||||
displayReanalyseBtn(dossier: Dossier): boolean {
|
||||
@ -26,7 +26,7 @@ export class PermissionsService {
|
||||
return this.isReviewerOrApprover(file) || file.isNew || (file.isError && file.isNew);
|
||||
}
|
||||
|
||||
isFileReviewer(file: File): boolean {
|
||||
isFileAssignee(file: File): boolean {
|
||||
return file.assignee === this._userService.currentUser.id;
|
||||
}
|
||||
|
||||
@ -37,19 +37,8 @@ export class PermissionsService {
|
||||
|
||||
canAssignToSelf(file: File): boolean {
|
||||
const dossier = this._getDossier(file);
|
||||
const precondition = this.isDossierMember(dossier) && !file.isProcessing && !file.isError && !file.isApproved;
|
||||
|
||||
const isTheOnlyReviewer = !dossier.hasReviewers;
|
||||
|
||||
if (precondition) {
|
||||
if (
|
||||
(file.isNew || (file.isUnderReview && !this.isFileReviewer(file))) &&
|
||||
(this.isApprover(dossier) || isTheOnlyReviewer || (this.isDossierReviewer(dossier) && file.isNew))
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
const precondition = this.isDossierMember(dossier) && !this.isFileAssignee(file) && !file.isError && !file.isProcessing;
|
||||
return precondition && (file.isNew || file.isUnderReview || (file.isUnderApproval && this.isApprover(dossier)));
|
||||
}
|
||||
|
||||
canAssignUser(file: File): boolean {
|
||||
@ -69,7 +58,7 @@ export class PermissionsService {
|
||||
|
||||
canUnassignUser(file: File): boolean {
|
||||
const dossier = this._getDossier(file);
|
||||
return (file.isUnderReview || file.isUnderApproval) && (this.isFileReviewer(file) || this.isApprover(dossier));
|
||||
return (file.isUnderReview || file.isUnderApproval) && (this.isFileAssignee(file) || this.isApprover(dossier));
|
||||
}
|
||||
|
||||
canSetUnderReview(file: File): boolean {
|
||||
@ -103,7 +92,7 @@ export class PermissionsService {
|
||||
|
||||
// TODO: Remove '?', after we make sure file is loaded before page
|
||||
canPerformAnnotationActions(file: File): boolean {
|
||||
return (file?.isUnderReview || file?.isUnderApproval) && this.isFileReviewer(file);
|
||||
return (file?.isUnderReview || file?.isUnderApproval) && this.isFileAssignee(file);
|
||||
}
|
||||
|
||||
canUndoApproval(file: File): boolean {
|
||||
@ -111,7 +100,7 @@ export class PermissionsService {
|
||||
}
|
||||
|
||||
canMarkPagesAsViewed(file: File): boolean {
|
||||
return (file.isUnderReview || file.isUnderApproval) && this.isFileReviewer(file);
|
||||
return (file.isUnderReview || file.isUnderApproval) && this.isFileAssignee(file);
|
||||
}
|
||||
|
||||
canDownloadFiles(file: File): boolean {
|
||||
@ -132,12 +121,12 @@ export class PermissionsService {
|
||||
}
|
||||
|
||||
canAddComment(file: File): boolean {
|
||||
return (this.isFileReviewer(file) || this.isApprover(this._getDossier(file))) && !file.isApproved;
|
||||
return (this.isFileAssignee(file) || this.isApprover(this._getDossier(file))) && !file.isApproved;
|
||||
}
|
||||
|
||||
canExcludePages(file: File): boolean {
|
||||
const dossier = this._getDossier(file);
|
||||
return (file.isUnderReview || file.isUnderApproval) && (this.isFileReviewer(file) || this.isApprover(dossier));
|
||||
return (file.isUnderReview || file.isUnderApproval) && (this.isFileAssignee(file) || this.isApprover(dossier));
|
||||
}
|
||||
|
||||
canDeleteComment(comment: IComment, file: File) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user