From 3ad82afc261e6c9b411544492aaecdb79c9f0b82 Mon Sep 17 00:00:00 2001 From: Timo Date: Mon, 12 Jul 2021 20:24:16 +0300 Subject: [PATCH] redaction log from backend pt. 1 --- .eslintrc.json | 2 +- .../src/app/models/file/file-data.model.ts | 222 ++---------------- .../file-preview-screen.component.ts | 15 +- .../services/pdf-viewer-data.service.ts | 21 +- .../services/file-download.service.ts | 2 +- .../services/file-upload.service.ts | 4 +- .../dossierAttributesController.service.ts | 5 +- .../src/lib/api/dossierController.service.ts | 5 +- .../api/fileManagementController.service.ts | 4 +- .../lib/api/redactionLogController.service.ts | 76 ++++++ 10 files changed, 118 insertions(+), 238 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 8d6e81f2e..32ca8c20e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -185,7 +185,7 @@ "max-len": [ "error", { - "code": 100, + "code": 140, "tabWidth": 4, "ignorePattern": "^import .*" } diff --git a/apps/red-ui/src/app/models/file/file-data.model.ts b/apps/red-ui/src/app/models/file/file-data.model.ts index c207e6656..40607a165 100644 --- a/apps/red-ui/src/app/models/file/file-data.model.ts +++ b/apps/red-ui/src/app/models/file/file-data.model.ts @@ -1,11 +1,4 @@ -import { - IdRemoval, - ManualRedactionEntry, - ManualRedactions, - RedactionChangeLog, - RedactionLog, - ViewedPages -} from '@redaction/red-ui-http'; +import { RedactionChangeLog, RedactionLog, ViewedPages } from '@redaction/red-ui-http'; import { FileStatusWrapper } from './file-status.wrapper'; import { UserWrapper } from '@services/user.service'; import { AnnotationWrapper } from './annotation.wrapper'; @@ -24,7 +17,6 @@ export class FileDataModel { public fileData: Blob, public redactionLog: RedactionLog, public redactionChangeLog: RedactionChangeLog, - public manualRedactions: ManualRedactions, public viewedPages?: ViewedPages ) {} @@ -34,7 +26,7 @@ export class FileDataModel { viewMode: ViewMode, areDevFeaturesEnabled: boolean ): AnnotationData { - const entries: RedactionLogEntryWrapper[] = this._convertData(dictionaryData); + const entries: RedactionLogEntryWrapper[] = this._convertData(); let allAnnotations = entries .map(entry => AnnotationWrapper.fromData(entry)) .filter(ann => !this.fileStatus.excludedPages.includes(ann.pageNumber)); @@ -59,10 +51,8 @@ export class FileDataModel { }; } - private _convertData(dictionaryData: { - [p: string]: TypeValueWrapper; - }): RedactionLogEntryWrapper[] { - let result: RedactionLogEntryWrapper[] = []; + private _convertData(): RedactionLogEntryWrapper[] { + const result: RedactionLogEntryWrapper[] = []; this.redactionChangeLog?.redactionLogEntry?.forEach(changeLogEntry => { if (changeLogEntry.changeType === 'REMOVED') { @@ -80,8 +70,6 @@ export class FileDataModel { Object.assign(redactionLogEntryWrapper, changeLogEntry); - redactionLogEntryWrapper.comments = - this.manualRedactions.comments[redactionLogEntryWrapper.id]; redactionLogEntryWrapper.isChangeLogEntry = true; redactionLogEntryWrapper.changeLogType = changeLogEntry.changeType; redactionLogEntryWrapper.id = 'changed-log-removed-' + redactionLogEntryWrapper.id; @@ -89,10 +77,16 @@ export class FileDataModel { } }); + const reasonAnnotationIds = []; this.redactionLog.redactionLogEntry?.forEach(redactionLogEntry => { - // false positive entries from the redaction-log need to be skipped - if (redactionLogEntry.type?.toLowerCase() === 'false_positive') { - return; + if ( + redactionLogEntry.manual && + (redactionLogEntry.status === 'APPROVED' || + redactionLogEntry.status === 'REQUESTED') + ) { + // for dictionary entries -> I.E accepted recommendations or false positives, + // check reason + reasonAnnotationIds.push(redactionLogEntry.reason); } const existingChangeLogEntry = this.redactionChangeLog?.redactionLogEntry?.find( @@ -104,204 +98,24 @@ export class FileDataModel { actionPendingReanalysis: false }; Object.assign(redactionLogEntryWrapper, redactionLogEntry); - redactionLogEntryWrapper.comments = - this.manualRedactions.comments[redactionLogEntryWrapper.id]; redactionLogEntryWrapper.isChangeLogEntry = !!existingChangeLogEntry; redactionLogEntryWrapper.changeLogType = 'ADDED'; result.push(redactionLogEntryWrapper); }); - this.manualRedactions.forceRedactions?.forEach(forceRedaction => { - const relevantRedactionLogEntry = result.find(r => r.id === forceRedaction.id); - - if (forceRedaction.status === 'DECLINED') { - relevantRedactionLogEntry.status = 'DECLINED'; - relevantRedactionLogEntry.userId = forceRedaction.user; - relevantRedactionLogEntry.dictionaryEntry = false; - relevantRedactionLogEntry.force = true; - return; - } - - // an entry for this request already exists in the redactionLog - if (relevantRedactionLogEntry) { - relevantRedactionLogEntry.userId = forceRedaction.user; - relevantRedactionLogEntry.dictionaryEntry = false; - relevantRedactionLogEntry.force = true; - - // if statuses differ - if ( - !forceRedaction.processedDate || - forceRedaction.status !== relevantRedactionLogEntry.status - ) { - relevantRedactionLogEntry.actionPendingReanalysis = true; - relevantRedactionLogEntry.status = forceRedaction.status; - } - } - }); - - this.manualRedactions.entriesToAdd?.forEach(manual => { - const markedAsReasonRedactionLogEntry = result.find(r => r.id === manual.reason); - - const relevantRedactionLogEntry = result.find(r => r.id === manual.id); - - // a redaction-log entry is marked as a reason for another entry - hide it - if (markedAsReasonRedactionLogEntry) { - if ( - !this._hasBeenProcessed(manual) || - !['APPROVED', 'DECLINED'].includes(manual.status) - ) { - markedAsReasonRedactionLogEntry.hidden = true; - } - } - - // an entry for this request already exists in the redactionLog - if (relevantRedactionLogEntry) { - if (relevantRedactionLogEntry.status === 'DECLINED') { - relevantRedactionLogEntry.hidden = true; - return; - } - - relevantRedactionLogEntry.userId = manual.user; - relevantRedactionLogEntry.dictionaryEntry = manual.addToDictionary; - - // if statuses differ - if (relevantRedactionLogEntry.status !== manual.status) { - relevantRedactionLogEntry.actionPendingReanalysis = true; - relevantRedactionLogEntry.status = manual.status; - } - } else { - // dictionary modifying requests that have been processed already updated - // the dictionary and should not be drawn - if (manual.addToDictionary && this._hasBeenProcessed(manual)) { - return; - } - - // no entry exists in the redaction log - create it - const dictionary = dictionaryData[manual.type]; - - const redactionLogEntryWrapper: RedactionLogEntryWrapper = {}; - - redactionLogEntryWrapper.id = manual.id; - redactionLogEntryWrapper.dictionaryEntry = manual.addToDictionary; - redactionLogEntryWrapper.legalBasis = manual.legalBasis; - redactionLogEntryWrapper.positions = manual.positions; - redactionLogEntryWrapper.reason = manual.reason; - redactionLogEntryWrapper.status = manual.status; - redactionLogEntryWrapper.type = manual.type; - redactionLogEntryWrapper.userId = manual.user; - redactionLogEntryWrapper.value = manual.value; - redactionLogEntryWrapper.redacted = !dictionary.hint; - redactionLogEntryWrapper.hint = dictionary.hint; - redactionLogEntryWrapper.manualRedactionType = 'ADD'; - redactionLogEntryWrapper.manual = true; - redactionLogEntryWrapper.comments = - this.manualRedactions.comments[redactionLogEntryWrapper.id]; - if (markedAsReasonRedactionLogEntry) { - // cleanup reason if the reason is another annotationId - // it is not needed for drawing - redactionLogEntryWrapper.reason = null; - } - - result.push(redactionLogEntryWrapper); - } - }); - - this.manualRedactions.idsToRemove?.forEach(idToRemove => { - const relevantRedactionLogEntry = result.find(r => r.id === idToRemove.id); - - if (!relevantRedactionLogEntry) { - // idRemove for something that doesn't exist - skip - return; - } else { - relevantRedactionLogEntry.userId = idToRemove.user; - relevantRedactionLogEntry.dictionaryEntry = idToRemove.removeFromDictionary; - - // if statuses differ - if (relevantRedactionLogEntry.status !== idToRemove.status) { - relevantRedactionLogEntry.actionPendingReanalysis = true; - relevantRedactionLogEntry.status = idToRemove.status; - } - - if (this._hasBeenProcessed(idToRemove)) { - if (idToRemove.status === 'DECLINED') { - relevantRedactionLogEntry.status = null; - } - } - } - }); - - this.manualRedactions.legalBasisChanges?.forEach(legalBasisChange => { - const relevantRedactionLogEntry = result.find(r => r.id === legalBasisChange.id); - - if (!relevantRedactionLogEntry) { - // legalBasisChanges for something that doesn't exist - skip - return; - } else { - relevantRedactionLogEntry.legalBasisChangeValue = legalBasisChange.legalBasis; - relevantRedactionLogEntry.userId = legalBasisChange.user; - // if statuses differ - if (relevantRedactionLogEntry.status !== legalBasisChange.status) { - relevantRedactionLogEntry.actionPendingReanalysis = true; - relevantRedactionLogEntry.status = legalBasisChange.status; - } - - if (this._hasBeenProcessed(legalBasisChange)) { - if (legalBasisChange.status === 'DECLINED') { - relevantRedactionLogEntry.status = null; - } - } - } - }); + this.redactionLog.redactionLogEntry = this.redactionLog.redactionLogEntry.filter( + r => reasonAnnotationIds.indexOf(r.id) < 0 + ); result.forEach(redactionLogEntry => { redactionLogEntry.legalBasisMapping = this.redactionLog.legalBasis; if (redactionLogEntry.manual) { - if (redactionLogEntry.manualRedactionType === 'ADD') { - const foundManualEntry = this.manualRedactions.entriesToAdd.find( - me => me.id === redactionLogEntry.id - ); - - // ADD has been undone - not yet processed - if (!foundManualEntry) { - redactionLogEntry.hidden = true; - } - } - - if (redactionLogEntry.manualRedactionType === 'LEGAL_BASIS_CHANGE') { - const legalBasisChanges = this.manualRedactions.legalBasisChanges.find( - me => me.id === redactionLogEntry.id - ); - // ADD has been undone - not yet processed - if (!legalBasisChanges) { - redactionLogEntry.manual = false; - redactionLogEntry.manualRedactionType = 'UNDO'; - redactionLogEntry.status = null; - } - } - if (redactionLogEntry.manualRedactionType === 'REMOVE') { - const foundManualEntry = this.manualRedactions.idsToRemove.find( - me => me.id === redactionLogEntry.id - ); - // REMOVE has been undone - not yet processed - if (!foundManualEntry) { - redactionLogEntry.manual = false; - redactionLogEntry.manualRedactionType = 'UNDO'; - redactionLogEntry.status = null; - } - } + console.log(redactionLogEntry); } }); - // remove undone entriesToAdd and idsToRemove - result = result.filter(redactionLogEntry => !redactionLogEntry.hidden); + console.log(result); return result; } - - private _hasBeenProcessed(entry: ManualRedactionEntry | IdRemoval): boolean { - return !entry.processedDate - ? false - : new Date(entry.processedDate).getTime() < - new Date(this.fileStatus.lastProcessed).getTime(); - } } diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts index 7ce682727..1296fe846 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts @@ -254,7 +254,6 @@ export class FilePreviewScreenComponent implements OnInit, OnDestroy, OnAttach, } async ngOnAttach(previousRoute: ActivatedRouteSnapshot) { - console.log('on attach'); if (!this.permissionsService.canOpenFile(this.appStateService.activeFile)) { await this._router.navigate(['/main/dossiers/' + this.dossierId]); return; @@ -633,7 +632,6 @@ export class FilePreviewScreenComponent implements OnInit, OnDestroy, OnAttach, this.fileData.redactionLog = fileData.redactionLog; this.fileData.redactionChangeLog = fileData.redactionChangeLog; this.fileData.fileStatus = fileData.fileStatus; - this.fileData.manualRedactions = fileData.manualRedactions; this.rebuildFilters(true); } else { this.fileData = fileData; @@ -657,9 +655,10 @@ export class FilePreviewScreenComponent implements OnInit, OnDestroy, OnAttach, /* Get the documentElement () to display the page in fullscreen */ private _cleanupAndRedrawManualAnnotations() { - this._fileDownloadService.loadActiveFileManualAnnotations().subscribe(manualRedactions => { - this.fileData.manualRedactions = manualRedactions; - this.rebuildFilters(); + this._fileDownloadService + .loadActiveFileRedactionLogPreview() + .subscribe(redactionLogPreview => { + this.fileData.redactionLog = redactionLogPreview; this._annotationDrawService.drawAnnotations( this._instance, this.annotationData.allAnnotations, @@ -674,8 +673,10 @@ export class FilePreviewScreenComponent implements OnInit, OnDestroy, OnAttach, const currentPageAnnotationIds = currentPageAnnotations.map(a => a.id); this.fileData.fileStatus = await this.appStateService.reloadActiveFile(); - this._fileDownloadService.loadActiveFileManualAnnotations().subscribe(manualRedactions => { - this.fileData.manualRedactions = manualRedactions; + this._fileDownloadService + .loadActiveFileRedactionLogPreview() + .subscribe(redactionLogPreview => { + this.fileData.redactionLog = redactionLogPreview; this.rebuildFilters(); if (this.viewMode === 'STANDARD') { currentPageAnnotationIds.forEach(id => { diff --git a/apps/red-ui/src/app/modules/dossier/services/pdf-viewer-data.service.ts b/apps/red-ui/src/app/modules/dossier/services/pdf-viewer-data.service.ts index c02562776..6f2aa7f80 100644 --- a/apps/red-ui/src/app/modules/dossier/services/pdf-viewer-data.service.ts +++ b/apps/red-ui/src/app/modules/dossier/services/pdf-viewer-data.service.ts @@ -3,7 +3,6 @@ import { forkJoin, Observable, of } from 'rxjs'; import { catchError, map } from 'rxjs/operators'; import { FileManagementControllerService, - ManualRedactionControllerService, RedactionLogControllerService, ViewedPagesControllerService } from '@redaction/red-ui-http'; @@ -18,13 +17,12 @@ export class PdfViewerDataService { private readonly _appStateService: AppStateService, private readonly _permissionsService: PermissionsService, private readonly _fileManagementControllerService: FileManagementControllerService, - private readonly _manualRedactionControllerService: ManualRedactionControllerService, private readonly _redactionLogControllerService: RedactionLogControllerService, private readonly _viewedPagesControllerService: ViewedPagesControllerService ) {} - loadActiveFileManualAnnotations() { - return this._manualRedactionControllerService.getManualRedaction( + loadActiveFileRedactionLogPreview() { + return this._redactionLogControllerService.getRedactionLogPreview( this._appStateService.activeDossierId, this._appStateService.activeFileId ); @@ -36,23 +34,16 @@ export class PdfViewerDataService { const file$ = this.downloadOriginalFile(this._appStateService.activeFile); const reactionLog$ = this._redactionLogControllerService - .getRedactionLog(dossierId, fileId) + .getRedactionLogPreview(dossierId, fileId) .pipe(catchError(() => of({}))); const redactionChangeLog$ = this._redactionLogControllerService .getRedactionChangeLog(dossierId, fileId) .pipe(catchError(() => of({}))); - const manualRedactions$ = this._manualRedactionControllerService - .getManualRedaction(dossierId, fileId) - .pipe(catchError(() => of({}))); const viewedPages$ = this.getViewedPagesForActiveFile(); - return forkJoin([ - file$, - reactionLog$, - redactionChangeLog$, - manualRedactions$, - viewedPages$ - ]).pipe(map(data => new FileDataModel(this._appStateService.activeFile, ...data))); + return forkJoin([file$, reactionLog$, redactionChangeLog$, viewedPages$]).pipe( + map(data => new FileDataModel(this._appStateService.activeFile, ...data)) + ); } getViewedPagesForActiveFile() { diff --git a/apps/red-ui/src/app/modules/upload-download/services/file-download.service.ts b/apps/red-ui/src/app/modules/upload-download/services/file-download.service.ts index 11ef47233..9b7287ad3 100644 --- a/apps/red-ui/src/app/modules/upload-download/services/file-download.service.ts +++ b/apps/red-ui/src/app/modules/upload-download/services/file-download.service.ts @@ -29,7 +29,7 @@ export class FileDownloadService { ) { interval(5000).subscribe(() => { if (_permissionsService.isUser()) { - this.getDownloadStatus().subscribe(() => {}); + this.getDownloadStatus().subscribe(() => {}); } }); } diff --git a/apps/red-ui/src/app/modules/upload-download/services/file-upload.service.ts b/apps/red-ui/src/app/modules/upload-download/services/file-upload.service.ts index fda32a8d5..0252f86ce 100644 --- a/apps/red-ui/src/app/modules/upload-download/services/file-upload.service.ts +++ b/apps/red-ui/src/app/modules/upload-download/services/file-upload.service.ts @@ -33,8 +33,8 @@ export class FileUploadService { private readonly _uploadControllerService: UploadControllerService, private readonly _dialogService: UploadDownloadDialogService ) { - this._uploadControllerService.defaultHeaders = - this._uploadControllerService.defaultHeaders.append('ngsw-bypass', 'true' ); + this._uploadControllerService.defaultHeaders = + this._uploadControllerService.defaultHeaders.append('ngsw-bypass', 'true'); interval(2500).subscribe(() => { this._handleUploads(); }); diff --git a/libs/red-ui-http/src/lib/api/dossierAttributesController.service.ts b/libs/red-ui-http/src/lib/api/dossierAttributesController.service.ts index d3cdb52e2..c50d8f8eb 100644 --- a/libs/red-ui-http/src/lib/api/dossierAttributesController.service.ts +++ b/libs/red-ui-http/src/lib/api/dossierAttributesController.service.ts @@ -11,8 +11,7 @@ */ /* tslint:disable:no-unused-variable member-ordering */ import { Inject, Injectable, Optional } from '@angular/core'; -import { HttpClient, HttpHeaders, HttpParams, HttpResponse, HttpEvent } from '@angular/common/http'; -import { CustomHttpUrlEncodingCodec } from '../encoder'; +import { HttpClient, HttpEvent, HttpHeaders, HttpResponse } from '@angular/common/http'; import { Observable } from 'rxjs'; @@ -22,7 +21,7 @@ import { DossierAttributesConfig } from '../model/dossierAttributesConfig'; import { DossierAttributesReq } from '../model/dossierAttributesReq'; import { DossierAttributesRes } from '../model/dossierAttributesRes'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH } from '../variables'; import { Configuration } from '../configuration'; @Injectable() diff --git a/libs/red-ui-http/src/lib/api/dossierController.service.ts b/libs/red-ui-http/src/lib/api/dossierController.service.ts index c6d07a5fb..946082ffa 100644 --- a/libs/red-ui-http/src/lib/api/dossierController.service.ts +++ b/libs/red-ui-http/src/lib/api/dossierController.service.ts @@ -11,15 +11,14 @@ */ /* tslint:disable:no-unused-variable member-ordering */ import { Inject, Injectable, Optional } from '@angular/core'; -import { HttpClient, HttpHeaders, HttpParams, HttpResponse, HttpEvent } from '@angular/common/http'; -import { CustomHttpUrlEncodingCodec } from '../encoder'; +import { HttpClient, HttpEvent, HttpHeaders, HttpResponse } from '@angular/common/http'; import { Observable } from 'rxjs'; import { Dossier } from '../model/dossier'; import { DossierRequest } from '../model/dossierRequest'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH } from '../variables'; import { Configuration } from '../configuration'; @Injectable() diff --git a/libs/red-ui-http/src/lib/api/fileManagementController.service.ts b/libs/red-ui-http/src/lib/api/fileManagementController.service.ts index 353616ea0..e65b0b80c 100644 --- a/libs/red-ui-http/src/lib/api/fileManagementController.service.ts +++ b/libs/red-ui-http/src/lib/api/fileManagementController.service.ts @@ -11,12 +11,12 @@ */ /* tslint:disable:no-unused-variable member-ordering */ import { Inject, Injectable, Optional } from '@angular/core'; -import { HttpClient, HttpHeaders, HttpParams, HttpResponse, HttpEvent } from '@angular/common/http'; +import { HttpClient, HttpEvent, HttpHeaders, HttpParams, HttpResponse } from '@angular/common/http'; import { CustomHttpUrlEncodingCodec } from '../encoder'; import { Observable } from 'rxjs'; -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { BASE_PATH } from '../variables'; import { Configuration } from '../configuration'; @Injectable() diff --git a/libs/red-ui-http/src/lib/api/redactionLogController.service.ts b/libs/red-ui-http/src/lib/api/redactionLogController.service.ts index 79a1aac09..501789180 100644 --- a/libs/red-ui-http/src/lib/api/redactionLogController.service.ts +++ b/libs/red-ui-http/src/lib/api/redactionLogController.service.ts @@ -201,6 +201,82 @@ export class RedactionLogControllerService { } ); } + /** + * Gets the redaction log preview + * None + * @param dossierId dossierId + * @param fileId fileId + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + public getRedactionLogPreview( + dossierId: string, + fileId: string, + observe?: 'body', + reportProgress?: boolean + ): Observable; + public getRedactionLogPreview( + dossierId: string, + fileId: string, + observe?: 'response', + reportProgress?: boolean + ): Observable>; + public getRedactionLogPreview( + dossierId: string, + fileId: string, + observe?: 'events', + reportProgress?: boolean + ): Observable>; + public getRedactionLogPreview( + dossierId: string, + fileId: string, + observe: any = 'body', + reportProgress: boolean = false + ): Observable { + if (dossierId === null || dossierId === undefined) { + throw new Error( + 'Required parameter dossierId was null or undefined when calling getRedactionLogPreview.' + ); + } + + if (fileId === null || fileId === undefined) { + throw new Error( + 'Required parameter fileId was null or undefined when calling getRedactionLogPreview.' + ); + } + + let headers = this.defaultHeaders; + + // authentication (RED-OAUTH) required + if (this.configuration.accessToken) { + const accessToken = + typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headers = headers.set('Authorization', 'Bearer ' + accessToken); + } + + // to determine the Accept header + const httpHeaderAccepts: string[] = ['application/json']; + const httpHeaderAcceptSelected: string | undefined = + this.configuration.selectHeaderAccept(httpHeaderAccepts); + if (httpHeaderAcceptSelected !== undefined) { + headers = headers.set('Accept', httpHeaderAcceptSelected); + } + + return this.httpClient.request( + 'get', + `${this.basePath}/sectionGrid/${encodeURIComponent( + String(dossierId) + )}/${encodeURIComponent(String(fileId))}/preview`, + { + withCredentials: this.configuration.withCredentials, + headers: headers, + observe: observe, + reportProgress: reportProgress + } + ); + } /** * Gets the section grid for a fileId