From 79daeb9178d05bef15635facea3f7815d0f95d21 Mon Sep 17 00:00:00 2001 From: Valentin Mihai Date: Sun, 9 Jul 2023 22:59:07 +0300 Subject: [PATCH] RED-6774 - updated redact/remove endpoints and permissions for users that are not approvers --- .../redact-text-dialog.component.ts | 4 ++- .../remove-redaction-dialog.component.ts | 3 ++ .../file-preview-screen.component.ts | 6 ++-- .../services/annotation-actions.service.ts | 10 ++++-- .../services/manual-redaction.service.ts | 31 ++----------------- .../services/pdf-proxy.service.ts | 3 +- libs/common-ui | 2 +- 7 files changed, 22 insertions(+), 37 deletions(-) diff --git a/apps/red-ui/src/app/modules/file-preview/dialogs/redact-text-dialog/redact-text-dialog.component.ts b/apps/red-ui/src/app/modules/file-preview/dialogs/redact-text-dialog/redact-text-dialog.component.ts index 70c794561..080bd28bd 100644 --- a/apps/red-ui/src/app/modules/file-preview/dialogs/redact-text-dialog/redact-text-dialog.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/dialogs/redact-text-dialog/redact-text-dialog.component.ts @@ -28,6 +28,7 @@ interface RedactTextData { dossierId: string; file: File; applyToAllDossiers: boolean; + isApprover: boolean; } interface DialogResult { @@ -202,7 +203,7 @@ export class RedactTextDialogComponent addRedactionRequest.value = addRedactionRequest.rectangle ? this.form.get('classification').value : this.form.get('selectedText').value; - addRedactionRequest.addToAllDossiers = this.dictionaryRequest && this.#applyToAllDossiers; + addRedactionRequest.addToAllDossiers = this.data.isApprover && this.dictionaryRequest && this.#applyToAllDossiers; } #options() { @@ -224,6 +225,7 @@ export class RedactTextDialogComponent extraOption: { label: this.#translations[this.type].inDossier.extraOptionLabel, checked: this.data.applyToAllDossiers ?? true, + hidden: !this.data.isApprover, }, }); } diff --git a/apps/red-ui/src/app/modules/file-preview/dialogs/remove-redaction-dialog/remove-redaction-dialog.component.ts b/apps/red-ui/src/app/modules/file-preview/dialogs/remove-redaction-dialog/remove-redaction-dialog.component.ts index 743ff5bcd..e783a0b4e 100644 --- a/apps/red-ui/src/app/modules/file-preview/dialogs/remove-redaction-dialog/remove-redaction-dialog.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/dialogs/remove-redaction-dialog/remove-redaction-dialog.component.ts @@ -27,6 +27,7 @@ export interface RemoveRedactionData { falsePositiveContext: string; permissions: RemoveRedactionPermissions; applyToAllDossiers: boolean; + isApprover: boolean; } export interface RemoveRedactionResult { @@ -109,6 +110,7 @@ export class RemoveRedactionDialogComponent extends IqserDialogComponent< extraOption: { label: this.#translations.IN_DOSSIER.extraOptionLabel, checked: this.data.applyToAllDossiers ?? true, + hidden: !this.data.isApprover, }, }); } @@ -122,6 +124,7 @@ export class RemoveRedactionDialogComponent extends IqserDialogComponent< extraOption: { label: this.#translations.FALSE_POSITIVE.extraOptionLabel, checked: this.data.applyToAllDossiers ?? true, + hidden: !this.data.isApprover, }, }); } 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 f4cb8f203..7f122e60a 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 @@ -354,12 +354,14 @@ export class FilePreviewScreenComponent async openRedactTextDialog(manualRedactionEntryWrapper: ManualRedactionEntryWrapper) { const file = this.state.file(); const dossierTemplate = this._dossierTemplatesService.find(this.state.dossierTemplateId); + const isApprover = this.permissionsService.isApprover(this.state.dossier()); const ref = this._iqserDialog.openDefault(RedactTextDialogComponent, { data: { manualRedactionEntryWrapper, dossierId: this.dossierId, file, - applyToAllDossiers: dossierTemplate.applyDictionaryUpdatesToAllDossiersByDefault, + applyToAllDossiers: isApprover ? dossierTemplate.applyDictionaryUpdatesToAllDossiersByDefault : false, + isApprover, }, }); @@ -370,7 +372,7 @@ export class FilePreviewScreenComponent const add$ = this._manualRedactionService.addAnnotation([result.redaction], this.dossierId, this.fileId, result.dictionary?.label); - if (result.applyToAllDossiers !== null) { + if (isApprover && result.applyToAllDossiers !== null) { const { ...body } = dossierTemplate; body.applyDictionaryUpdatesToAllDossiersByDefault = result.applyToAllDossiers; await this._dossierTemplatesService.createOrUpdate(body); diff --git a/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts b/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts index 6d8db68f3..19397e5d2 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts @@ -38,6 +38,7 @@ import { RemoveRedactionOptions } from '../dialogs/remove-redaction-dialog/remov import { IqserDialog } from '../../../../../../../libs/common-ui/src/lib/dialog/iqser-dialog.service'; import { DossierTemplatesService } from '@services/dossier-templates/dossier-templates.service'; import { isJustOne, List } from '@iqser/common-ui/lib/utils'; +import { PermissionsService } from '@services/permissions.service'; @Injectable() export class AnnotationActionsService { @@ -54,6 +55,7 @@ export class AnnotationActionsService { private readonly _fileDataService: FileDataService, private readonly _skippedService: SkippedService, private readonly _dossierTemplatesService: DossierTemplatesService, + private readonly _permissionsService: PermissionsService, ) {} acceptSuggestion(annotations: AnnotationWrapper[]) { @@ -126,6 +128,7 @@ export class AnnotationActionsService { canMarkAsFalsePositive: permissions.canMarkAsFalsePositive, }; const dossierTemplate = this._dossierTemplatesService.find(this._state.dossierTemplateId); + const isApprover = this._permissionsService.isApprover(this._state.dossier()); const result: RemoveRedactionResult = await this._iqserDialog .openDefault(RemoveRedactionDialogComponent, { @@ -134,7 +137,8 @@ export class AnnotationActionsService { dossier: this._state.dossier(), falsePositiveContext: this._getFalsePositiveText(redaction), permissions: removePermissions, - applyToAllDossiers: dossierTemplate.applyDictionaryUpdatesToAllDossiersByDefault, + applyToAllDossiers: isApprover ? dossierTemplate.applyDictionaryUpdatesToAllDossiersByDefault : false, + isApprover, }, }) .result(); @@ -146,7 +150,7 @@ export class AnnotationActionsService { this.#removeRedaction(redaction, result); } - if (result.option.extraOption) { + if (isApprover && result.option.extraOption) { const { ...body } = dossierTemplate; body.applyDictionaryUpdatesToAllDossiersByDefault = result.option.extraOption.checked; await this._dossierTemplatesService.createOrUpdate(body); @@ -409,7 +413,7 @@ export class AnnotationActionsService { }; const { dossierId, fileId } = this._state; this.#processObsAndEmit( - this._manualRedactionService.removeOrSuggestRemove([body], dossierId, fileId, removeFromDictionary, redaction.isHint), + this._manualRedactionService.removeRedaction([body], dossierId, fileId, removeFromDictionary, redaction.isHint), ).then(); } } diff --git a/apps/red-ui/src/app/modules/file-preview/services/manual-redaction.service.ts b/apps/red-ui/src/app/modules/file-preview/services/manual-redaction.service.ts index 6935802b5..1f4d040ce 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/manual-redaction.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/manual-redaction.service.ts @@ -97,15 +97,10 @@ export class ManualRedactionService extends GenericService { addAnnotation(requests: List, dossierId: string, fileId: string, dictionaryLabel?: string) { const toast = requests[0].addToDictionary ? this.#showAddToDictionaryToast(requests, dictionaryLabel) : this.#showToast('add'); const canAddRedaction = this._iqaerPermissionsService.has(Roles.redactions.write); - if (canAddRedaction && this._permissionsService.isApprover(this.#dossier(dossierId))) { + if (canAddRedaction) { return this.add(requests, dossierId, fileId).pipe(toast); } - const canRequestRedaction = this._iqaerPermissionsService.has(Roles.redactions.request); - if (canRequestRedaction) { - return this.requestAdd(requests, dossierId, fileId).pipe(toast); - } - return of(undefined); } @@ -141,20 +136,8 @@ export class ManualRedactionService extends GenericService { return this.requestResize(requests, dossierId, fileId); } - removeOrSuggestRemove( - body: List, - dossierId: string, - fileId: string, - removeFromDictionary = false, - isHint = false, - ) { - if (this._permissionsService.isApprover(this.#dossier(dossierId))) { - return this.remove(body, dossierId, fileId).pipe(this.#showToast(!isHint ? 'remove' : 'remove-hint', removeFromDictionary)); - } - - return this.requestRemoveRedaction(body, dossierId, fileId).pipe( - this.#showToast(!isHint ? 'request-remove' : 'request-remove-hint', removeFromDictionary), - ); + removeRedaction(body: List, dossierId: string, fileId: string, removeFromDictionary = false, isHint = false) { + return this.remove(body, dossierId, fileId).pipe(this.#showToast(!isHint ? 'remove' : 'remove-hint', removeFromDictionary)); } getTitle(type: ManualRedactionEntryType) { @@ -194,10 +177,6 @@ export class ManualRedactionService extends GenericService { ); } - requestRemoveRedaction(body: List, dossierId: string, fileId: string) { - return this._post(body, `${this.#bulkRequest}/remove/${dossierId}/${fileId}`).pipe(this.#log('Request remove', body)); - } - approve(annotationIds: List, dossierId: string, fileId: string) { return this._post(annotationIds, `${this._defaultModelPath}/bulk/approve/${dossierId}/${fileId}`).pipe( this.#log('Approve', annotationIds), @@ -220,10 +199,6 @@ export class ManualRedactionService extends GenericService { return this._post(body, `${this.#bulkRedaction}/remove/${dossierId}/${fileId}`).pipe(this.#log('Remove', body)); } - requestAdd(body: List, dossierId: string, fileId: string) { - return this._post(body, `${this.#bulkRequest}/add/${dossierId}/${fileId}`).pipe(this.#log('Request add', body)); - } - forceRedaction(body: List, dossierId: string, fileId: string) { return this._post(body, `${this.#bulkRedaction}/force/${dossierId}/${fileId}`).pipe(this.#log('Force redaction', body)); } diff --git a/apps/red-ui/src/app/modules/file-preview/services/pdf-proxy.service.ts b/apps/red-ui/src/app/modules/file-preview/services/pdf-proxy.service.ts index a6a71e2a1..b21363ca4 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/pdf-proxy.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/pdf-proxy.service.ts @@ -178,8 +178,7 @@ export class PdfProxyService { }); } - const isApprover = this._permissionsService.isApprover(this._state.dossier()); - if (this._iqserPermissionsService.has(Roles.redactions.write) && isApprover) { + if (this._iqserPermissionsService.has(Roles.redactions.write)) { popups.push({ type: 'actionButton', dataElement: TextPopups.REDACT_TEXT, diff --git a/libs/common-ui b/libs/common-ui index 137a62338..a4e425d37 160000 --- a/libs/common-ui +++ b/libs/common-ui @@ -1 +1 @@ -Subproject commit 137a62338ce5c890fe337ab8da8bbe9279463730 +Subproject commit a4e425d3739d6145325a8fe347d9fcae1e12a662