From d9dbf394b742f706f3726b2bc610f1ede97fe044 Mon Sep 17 00:00:00 2001 From: Salim Terres Date: Tue, 8 Sep 2026 10:52:48 +0200 Subject: [PATCH] Bug #16825: [Chain audit] 404 error when downloading the report of a failed chaining audit. --- .../audit-preview.component.spec.ts | 20 +++++++++++++++++++ .../audit-preview/audit-preview.component.ts | 9 +++++++-- .../logbook-download.service.ts | 4 ++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/ui/ui-frontend/projects/referential/src/app/audit/audit-preview/audit-preview.component.spec.ts b/ui/ui-frontend/projects/referential/src/app/audit/audit-preview/audit-preview.component.spec.ts index c5e26088dfe..f7f1f7de9d6 100644 --- a/ui/ui-frontend/projects/referential/src/app/audit/audit-preview/audit-preview.component.spec.ts +++ b/ui/ui-frontend/projects/referential/src/app/audit/audit-preview/audit-preview.component.spec.ts @@ -91,4 +91,24 @@ describe('AuditPreviewComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); + + it('should report no report for a chain audit without a successful reporting sub-event', () => { + fixture.componentRef.setInput('audit', { + type: 'TRACEABILITY_CHAIN_AUDIT', + events: [{ type: 'STP_PREPARE_TRACEABILITY_CHAIN_AUDIT', outcome: 'KO', outDetail: 'STP_PREPARE_TRACEABILITY_CHAIN_AUDIT.KO' }], + }); + fixture.detectChanges(); + + expect(component.hasReport()).toBe(false); + }); + + it('should report a report for a chain audit with a successful reporting sub-event, even when the audit is KO', () => { + fixture.componentRef.setInput('audit', { + type: 'TRACEABILITY_CHAIN_AUDIT', + events: [{ type: 'TRACEABILITY_CHAIN_AUDIT_REPORTING', outcome: 'OK', outDetail: 'TRACEABILITY_CHAIN_AUDIT_REPORTING.OK' }], + }); + fixture.detectChanges(); + + expect(component.hasReport()).toBe(true); + }); }); diff --git a/ui/ui-frontend/projects/referential/src/app/audit/audit-preview/audit-preview.component.ts b/ui/ui-frontend/projects/referential/src/app/audit/audit-preview/audit-preview.component.ts index 3779ef96c4f..173e3ad6a8d 100644 --- a/ui/ui-frontend/projects/referential/src/app/audit/audit-preview/audit-preview.component.ts +++ b/ui/ui-frontend/projects/referential/src/app/audit/audit-preview/audit-preview.component.ts @@ -77,9 +77,14 @@ export class AuditPreviewComponent implements OnInit { accessContractId: string; hasReport: Signal = computed(() => { - if (this.audit().type === 'EVIDENCE_AUDIT') { + const audit = this.audit(); + if (audit.type === 'EVIDENCE_AUDIT') { // Evidence audit may not have a report if "data" has "No report generated" in it. - return !this.audit().events.some((e) => /No report generated/i.test(e.data)); + return !audit.events.some((e) => /No report generated/i.test(e.data)); + } + if (audit.type === AuditOperation.TRACEABILITY_CHAIN_AUDIT) { + // Chain audit report only exists once the reporting sub-step has completed successfully. + return audit.events.some((e) => /REPORTING$/i.test(e.type) && e.outcome === 'OK'); } return true; }); diff --git a/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-download.service.ts b/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-download.service.ts index 37a5d4c70c9..8b1de7f1cfb 100644 --- a/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-download.service.ts +++ b/ui/ui-frontend/projects/referential/src/app/logbook-operation/logbook-download.service.ts @@ -239,6 +239,10 @@ export class LogbookDownloadService extends SearchService { // Evidence audit may not have a report if "data" has "No report generated" in it. return !event.events.some((e) => /No report generated/i.test(e.data)); } + if (['TRACEABILITY_CHAIN_AUDIT'].includes(event.type)) { + // Chain audit report only exists once the reporting sub-step has completed successfully. + return event.events.some((e) => /REPORTING$/i.test(e.type) && e.outcome === 'OK'); + } return true; } }