redaction log from backend pt. 1

This commit is contained in:
Timo 2021-07-12 20:24:16 +03:00
parent eee2091927
commit 3ad82afc26
10 changed files with 118 additions and 238 deletions

View File

@ -185,7 +185,7 @@
"max-len": [
"error",
{
"code": 100,
"code": 140,
"tabWidth": 4,
"ignorePattern": "^import .*"
}

View File

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

View File

@ -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 (<html>) 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 => {

View File

@ -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() {

View File

@ -29,7 +29,7 @@ export class FileDownloadService {
) {
interval(5000).subscribe(() => {
if (_permissionsService.isUser()) {
this.getDownloadStatus().subscribe(() => {});
this.getDownloadStatus().subscribe(() => {});
}
});
}

View File

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

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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<RedactionLog>;
public getRedactionLogPreview(
dossierId: string,
fileId: string,
observe?: 'response',
reportProgress?: boolean
): Observable<HttpResponse<RedactionLog>>;
public getRedactionLogPreview(
dossierId: string,
fileId: string,
observe?: 'events',
reportProgress?: boolean
): Observable<HttpEvent<RedactionLog>>;
public getRedactionLogPreview(
dossierId: string,
fileId: string,
observe: any = 'body',
reportProgress: boolean = false
): Observable<any> {
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<RedactionLog>(
'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