diff --git a/package.json b/package.json index a273376dde..fb92936b2c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hmcts/ccd-case-ui-toolkit", - "version": "7.1.37", + "version": "7.1.37-docstore-v2-exclusion-2", "engines": { "node": ">=18.19.0" }, diff --git a/projects/ccd-case-ui-toolkit/package.json b/projects/ccd-case-ui-toolkit/package.json index a973fb5d6e..9a2f6a74e7 100644 --- a/projects/ccd-case-ui-toolkit/package.json +++ b/projects/ccd-case-ui-toolkit/package.json @@ -1,6 +1,6 @@ { "name": "@hmcts/ccd-case-ui-toolkit", - "version": "7.1.37", + "version": "7.1.37-docstore-v2-exclusion-2", "engines": { "node": ">=18.19.0" }, diff --git a/projects/ccd-case-ui-toolkit/src/lib/app-config.mock.ts b/projects/ccd-case-ui-toolkit/src/lib/app-config.mock.ts index ce40020ae1..cd13c7b173 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/app-config.mock.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/app-config.mock.ts @@ -151,6 +151,10 @@ export class AppMockConfig implements AbstractAppConfig { return false; } + public getDocumentSecureModeCaseTypeExclusions(): string { + return ''; + } + public getWAServiceConfig(): any { return null; } diff --git a/projects/ccd-case-ui-toolkit/src/lib/app.config.ts b/projects/ccd-case-ui-toolkit/src/lib/app.config.ts index a780e2d3d6..4a63f40b99 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/app.config.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/app.config.ts @@ -32,6 +32,7 @@ export abstract class AbstractAppConfig { public abstract getDocumentManagementUrl(): string; public abstract getDocumentManagementUrlV2(): string; public abstract getDocumentSecureMode(): boolean; + public abstract getDocumentSecureModeCaseTypeExclusions(): string; public abstract getRemoteDocumentManagementUrl(): string; public abstract getHrsUrl(): string; public abstract getRemoteHrsUrl(): string; @@ -129,6 +130,7 @@ export class CaseEditorConfig { public document_management_url_v2: string; public hrs_url: string; public document_management_secure_enabled: boolean; + public documentSecureModeCaseTypeExclusions: string; public login_url: string; public oauth2_client_id: string; public postcode_lookup_url: string; diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/waystopay/waystopay-field.component.spec.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/waystopay/waystopay-field.component.spec.ts index c554daf68e..2d5a345474 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/waystopay/waystopay-field.component.spec.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/waystopay/waystopay-field.component.spec.ts @@ -33,6 +33,7 @@ const APP_CONFIG: AbstractAppConfig = { getDocumentManagementUrl: () => 'documentManagementUrl', getDocumentManagementUrlV2: () => 'documentManagementUrlV2', getDocumentSecureMode: () => true, + getDocumentSecureModeCaseTypeExclusions: () => 'DIVORCE', getRemoteDocumentManagementUrl: () => 'remoteDocumentManagementUrl', getHrsUrl: () => 'hrsUrl', getRemoteHrsUrl: () => 'remoteHrsUrl', diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/services/document-management/document-management.service.spec.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/services/document-management/document-management.service.spec.ts index 3b2182b306..4400c3cd4d 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/services/document-management/document-management.service.spec.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/services/document-management/document-management.service.spec.ts @@ -6,6 +6,7 @@ import { AbstractAppConfig } from '../../../app.config'; import { CaseField, DocumentData, FieldType } from '../../domain'; import { HttpService } from '../http'; import { DocumentManagementService } from './document-management.service'; +import { CaseNotifier } from '../../components/case-editor/services/case.notifier'; describe('DocumentManagementService', () => { const DOCUMENT_MANAGEMENT_URL = 'https://www.example.com/binary'; @@ -15,23 +16,25 @@ describe('DocumentManagementService', () => { let appConfig: any; let httpService: any; - + let caseNotifier: any; let documentManagementService: DocumentManagementService; beforeEach(waitForAsync(() => { appConfig = createSpyObj('appConfig', [ 'getDocumentManagementUrl', 'getRemoteDocumentManagementUrl', 'getHrsUrl', 'getRemoteHrsUrl', - 'getAnnotationApiUrl', 'getDocumentSecureMode' + 'getAnnotationApiUrl', 'getDocumentSecureMode', 'getDocumentSecureModeCaseTypeExclusions', 'getDocumentManagementUrlV2' ]); appConfig.getRemoteDocumentManagementUrl.and.returnValue(REMOTE_DOCUMENT_MANAGEMENT_URL); appConfig.getDocumentManagementUrl.and.returnValue(DOCUMENT_MANAGEMENT_URL); appConfig.getRemoteHrsUrl.and.returnValue(REMOTE_HRS_URL); appConfig.getHrsUrl.and.returnValue(HRS_URL); appConfig.getDocumentSecureMode.and.returnValue(false); - + appConfig.getDocumentSecureModeCaseTypeExclusions.and.returnValue(''); + caseNotifier = createSpyObj('caseNotifier', ['caseView']); httpService = createSpyObj('httpService', ['post']); - documentManagementService = new DocumentManagementService(httpService, appConfig); + caseNotifier.caseView = of({ case_type: { id: 'test' } }); + documentManagementService = new DocumentManagementService(httpService, appConfig, caseNotifier); })); describe('uploadFile', () => { @@ -84,6 +87,75 @@ describe('DocumentManagementService', () => { })); }); + describe('getDocStoreUrl', () => { + const CASE_TYPE_ID = 'caseType1'; + const NO_EXCLUDED_CASE_TYPE_ID = ''; + const EXCLUDED_CASE_TYPE_ID = 'excludedCaseType'; + const EXCLUDED_CASE_TYPE_ID_MULTIPLE_TYPES = 'excludedCaseType,excludedCaseType2'; + const DOCUMENT_MANAGEMENT_URL = 'https://www.example.com/documents'; + const DOCUMENT_MANAGEMENT_URL_V2 = 'https://www.example.com/documents/v2'; + + beforeEach(() => { + caseNotifier = createSpyObj('caseNotifier', ['caseView']); + appConfig.getDocumentManagementUrl.and.returnValue(DOCUMENT_MANAGEMENT_URL); + appConfig.getDocumentManagementUrlV2.and.returnValue(DOCUMENT_MANAGEMENT_URL_V2); + }); + + it('should return DocumentManagementUrlV2 when document secure mode is enabled and case type is not in exclusion list', () => { + appConfig.getDocumentSecureMode.and.returnValue(true); + appConfig.getDocumentSecureModeCaseTypeExclusions.and.returnValue(EXCLUDED_CASE_TYPE_ID); + caseNotifier.caseView = of({ case_type: { id: CASE_TYPE_ID } }); + documentManagementService = new DocumentManagementService(httpService, appConfig, caseNotifier); + const url = documentManagementService['getDocStoreUrl'](); + expect(url).toBe(DOCUMENT_MANAGEMENT_URL_V2); + }); + + it('should return DocumentManagementUrl when document secure mode is enabled and case type is in exclusion list', () => { + appConfig.getDocumentSecureMode.and.returnValue(true); + appConfig.getDocumentSecureModeCaseTypeExclusions.and.returnValue(EXCLUDED_CASE_TYPE_ID); + caseNotifier.caseView = of({ case_type: { id: EXCLUDED_CASE_TYPE_ID } }); + documentManagementService = new DocumentManagementService(httpService, appConfig, caseNotifier); + const url = documentManagementService['getDocStoreUrl'](); + expect(url).toBe(DOCUMENT_MANAGEMENT_URL); + }); + + it('should return DocumentManagementUrl when document secure mode is disabled', () => { + appConfig.getDocumentSecureMode.and.returnValue(false); + appConfig.getDocumentSecureModeCaseTypeExclusions.and.returnValue(EXCLUDED_CASE_TYPE_ID); + caseNotifier.caseView = of({ case_type: { id: CASE_TYPE_ID } }); + documentManagementService = new DocumentManagementService(httpService, appConfig, caseNotifier); + const url = documentManagementService['getDocStoreUrl'](); + expect(url).toBe(DOCUMENT_MANAGEMENT_URL); + }); + + it('should return DocumentManagementUrlV2 when exclusions contains multiple values and file is not excluded', () => { + appConfig.getDocumentSecureMode.and.returnValue(true); + appConfig.getDocumentSecureModeCaseTypeExclusions.and.returnValue(EXCLUDED_CASE_TYPE_ID_MULTIPLE_TYPES); + caseNotifier.caseView = of({ case_type: { id: 'excludedCaseType3' } }); + documentManagementService = new DocumentManagementService(httpService, appConfig, caseNotifier); + const url = documentManagementService['getDocStoreUrl'](); + expect(url).toBe(DOCUMENT_MANAGEMENT_URL_V2); + }); + + it('should return DocumentManagementUrl when exclusions contains multiple values and file is excluded', () => { + appConfig.getDocumentSecureMode.and.returnValue(true); + appConfig.getDocumentSecureModeCaseTypeExclusions.and.returnValue(EXCLUDED_CASE_TYPE_ID_MULTIPLE_TYPES); + caseNotifier.caseView = of({ case_type: { id: 'excludedCaseType2' } }); + documentManagementService = new DocumentManagementService(httpService, appConfig, caseNotifier); + const url = documentManagementService['getDocStoreUrl'](); + expect(url).toBe(DOCUMENT_MANAGEMENT_URL); + }); + + it('should handle when there is no files in exclusion list', () => { + appConfig.getDocumentSecureMode.and.returnValue(true); + appConfig.getDocumentSecureModeCaseTypeExclusions.and.returnValue(NO_EXCLUDED_CASE_TYPE_ID); + caseNotifier.caseView = of({ case_type: { id: 'caseType2' } }); + documentManagementService = new DocumentManagementService(httpService, appConfig, caseNotifier); + const url = documentManagementService['getDocStoreUrl'](); + expect(url).toBe(DOCUMENT_MANAGEMENT_URL_V2); + }); + }); + describe('Media viewer', () => { const FIELD_TYPE: FieldType = { id: 'Collection', diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/services/document-management/document-management.service.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/services/document-management/document-management.service.ts index a73e349090..a952459f7f 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/services/document-management/document-management.service.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/services/document-management/document-management.service.ts @@ -5,6 +5,7 @@ import { delay } from 'rxjs/operators'; import { AbstractAppConfig } from '../../../app.config'; import { DocumentData } from '../../domain/document/document-data.model'; import { HttpService } from '../http'; +import { CaseNotifier } from '../../components/case-editor/services/case.notifier'; @Injectable() export class DocumentManagementService { @@ -25,7 +26,7 @@ export class DocumentManagementService { private static readonly excelList: string[] = ['XLS', 'XLSX', 'xls', 'xlsx']; private static readonly powerpointList: string[] = ['PPT', 'PPTX', 'ppt', 'pptx']; - constructor(private readonly http: HttpService, private readonly appConfig: AbstractAppConfig) {} + constructor(private readonly http: HttpService, private readonly appConfig: AbstractAppConfig, private readonly caseNotifierService: CaseNotifier) {} public uploadFile(formData: FormData): Observable { const url = this.getDocStoreUrl(); @@ -103,6 +104,14 @@ export class DocumentManagementService { } private getDocStoreUrl(): string { - return this.appConfig.getDocumentSecureMode() ? this.appConfig.getDocumentManagementUrlV2() : this.appConfig.getDocumentManagementUrl(); + let docStoreUrl = ''; + this.caseNotifierService.caseView.subscribe((caseDetails) => { + const caseType = caseDetails?.case_type?.id; + const documentSecureModeCaseTypeExclusions = this.appConfig.getDocumentSecureModeCaseTypeExclusions()?.split(','); + const isDocumentOnExclusionList = documentSecureModeCaseTypeExclusions?.includes(caseType); + const documentSecureModeEnabled = this.appConfig.getDocumentSecureMode(); + docStoreUrl = (documentSecureModeEnabled && !isDocumentOnExclusionList) ? this.appConfig.getDocumentManagementUrlV2() : this.appConfig.getDocumentManagementUrl(); + }).unsubscribe(); + return docStoreUrl; } }