diff --git a/apps/red-ui/src/app/models/file/file-status.wrapper.ts b/apps/red-ui/src/app/models/file/file-status.wrapper.ts index f05e81f54..5296eee52 100644 --- a/apps/red-ui/src/app/models/file/file-status.wrapper.ts +++ b/apps/red-ui/src/app/models/file/file-status.wrapper.ts @@ -22,6 +22,10 @@ export class FileStatusWrapper { } } + get dossierDictionaryVersion() { + return this.fileStatus.dossierDictionaryVersion; + } + get analysisDuration() { return this.fileStatus.analysisDuration; } diff --git a/apps/red-ui/src/app/modules/projects/dialogs/dossier-dictionary-dialog/dossier-dictionary-dialog.component.ts b/apps/red-ui/src/app/modules/projects/dialogs/dossier-dictionary-dialog/dossier-dictionary-dialog.component.ts index e36e77d7d..21e4cd537 100644 --- a/apps/red-ui/src/app/modules/projects/dialogs/dossier-dictionary-dialog/dossier-dictionary-dialog.component.ts +++ b/apps/red-ui/src/app/modules/projects/dialogs/dossier-dictionary-dialog/dossier-dictionary-dialog.component.ts @@ -29,7 +29,8 @@ export class DossierDictionaryDialogComponent { 'dossier_redaction', this.project.projectId ) - .subscribe(() => { + .subscribe(async () => { + await this._appStateService.updateProjectDictionaryVersion(this.project); this._appStateService.updateProjectDictionary(this.project.ruleSetId, this.project.projectId); this.dialogRef.close(); }); diff --git a/apps/red-ui/src/app/services/permissions.service.ts b/apps/red-ui/src/app/services/permissions.service.ts index 8d7517faa..ff22c66e8 100644 --- a/apps/red-ui/src/app/services/permissions.service.ts +++ b/apps/red-ui/src/app/services/permissions.service.ts @@ -43,12 +43,9 @@ export class PermissionsService { if (!fileStatus) { return false; } - const project = this._appStateService.getProjectById(fileStatus.projectId); return ( ((fileStatus.status === 'UNASSIGNED' || fileStatus.status === 'UNDER_REVIEW' || fileStatus.status === 'UNDER_APPROVAL') && - (fileStatus.dictionaryVersion !== this._appStateService.dictionaryVersion(project.ruleSetId) || - fileStatus.rulesVersion !== this._appStateService.rulesVersion(project.ruleSetId) || - fileStatus.hasUnappliedSuggestions)) || + (!this._appStateService.fileIsUpToDateWithLatestVersions(fileStatus) || fileStatus.hasUnappliedSuggestions)) || fileStatus.isError ); } @@ -137,7 +134,7 @@ export class PermissionsService { if (!fileStatus) { return false; } - return !fileStatus.hasRequests && !fileStatus.hasUnappliedSuggestions && this._appStateService.isFileUpToDateWithDictionaryAndRules(fileStatus); + return !fileStatus.hasRequests && !fileStatus.hasUnappliedSuggestions && this._appStateService.fileIsUpToDateWithLatestVersions(fileStatus); } canSetUnderApproval(fileStatus?: FileStatusWrapper) { diff --git a/apps/red-ui/src/app/state/app-state.service.ts b/apps/red-ui/src/app/state/app-state.service.ts index 713af7993..d38e417c6 100644 --- a/apps/red-ui/src/app/state/app-state.service.ts +++ b/apps/red-ui/src/app/state/app-state.service.ts @@ -177,24 +177,33 @@ export class AppStateService { if (this.activeProject?.hasPendingOrProcessing) { await this.reloadActiveProjectFiles(); await this.updateDictionaryVersion(); + await this.updateProjectDictionaryVersion(this.activeProject); } } - isFileUpToDateWithDictionaryAndRules(fileStatus?: FileStatusWrapper) { + fileIsUpToDateWithLatestVersions(fileStatus?: FileStatusWrapper) { if (!fileStatus) { fileStatus = this.activeFile; } - return fileStatus.dictionaryVersion === this.dictionaryVersion() && fileStatus.rulesVersion === this.rulesVersion(); + + const project = this.getProjectById(fileStatus.projectId); + const ruleSetId = project.ruleSetId; + + return ( + fileStatus.dictionaryVersion === this._dictionaryVersion(ruleSetId) && + fileStatus.rulesVersion === this._rulesVersion(ruleSetId) && + (!project.dictionaryVersion || fileStatus.dossierDictionaryVersion === project.dictionaryVersion) + ); } - dictionaryVersion(ruleSetId?: string) { + private _dictionaryVersion(ruleSetId?: string) { if (!ruleSetId) { ruleSetId = this.activeProject.ruleSetId; } return this._appState.versions[ruleSetId].dictionaryVersion; } - rulesVersion(ruleSetId?: string) { + private _rulesVersion(ruleSetId?: string) { if (!ruleSetId) { ruleSetId = this.activeProject.ruleSetId; } @@ -270,6 +279,8 @@ export class AppStateService { this._appState.projects = mappedProjects; this._computeStats(); + + this.updateProjectDictionaryVersions(); } } @@ -611,6 +622,18 @@ export class AppStateService { this._appState.versions = await this._versionsControllerService.getVersions(ruleSetIds).toPromise(); } + updateProjectDictionaryVersions() { + debugger; + for (const project of this.allProjects) { + // don't wait / block + this.updateProjectDictionaryVersion(project); + } + } + + async updateProjectDictionaryVersion(project: ProjectWrapper) { + project.dictionaryVersion = await this._versionsControllerService.getDossierDictionaryVersion(project.projectId, project.ruleSetId).toPromise(); + } + private _getExistingFiles(projectId: string) { const found = this._appState.projects.find((p) => p.project.projectId === projectId); return found ? found.files : []; diff --git a/apps/red-ui/src/app/state/model/project.wrapper.ts b/apps/red-ui/src/app/state/model/project.wrapper.ts index aecbcd1af..f2827c1d0 100644 --- a/apps/red-ui/src/app/state/model/project.wrapper.ts +++ b/apps/red-ui/src/app/state/model/project.wrapper.ts @@ -13,6 +13,7 @@ export class ProjectWrapper { allFilesApproved?: boolean; type: Dictionary; + dictionaryVersion?: number; constructor(public project: Project, files: FileStatusWrapper[]) { this._files = files ? files : []; diff --git a/libs/red-ui-http/src/lib/model/fileStatus.ts b/libs/red-ui-http/src/lib/model/fileStatus.ts index 9e9b88431..65265ec22 100644 --- a/libs/red-ui-http/src/lib/model/fileStatus.ts +++ b/libs/red-ui-http/src/lib/model/fileStatus.ts @@ -39,6 +39,13 @@ export interface FileStatus { * Shows which dictionary versions was used during the analysis. */ dictionaryVersion?: number; + /** + * dossier dictionary version + */ + dossierDictionaryVersion?: number; + /** + * File Attributes; + */ fileAttributes?: FileAttributes; /** * The ID of the file.