Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EXUI-2640 - Add exclusion list code for doc store url #1867

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion projects/ccd-case-ui-toolkit/package.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down
4 changes: 4 additions & 0 deletions projects/ccd-case-ui-toolkit/src/lib/app-config.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ export class AppMockConfig implements AbstractAppConfig {
return false;
}

public getDocumentSecureModeCaseTypeExclusions(): string {
return '';
}

public getWAServiceConfig(): any {
return null;
}
Expand Down
2 changes: 2 additions & 0 deletions projects/ccd-case-ui-toolkit/src/lib/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const APP_CONFIG: AbstractAppConfig = {
getDocumentManagementUrl: () => 'documentManagementUrl',
getDocumentManagementUrlV2: () => 'documentManagementUrlV2',
getDocumentSecureMode: () => true,
getDocumentSecureModeCaseTypeExclusions: () => 'DIVORCE',
getRemoteDocumentManagementUrl: () => 'remoteDocumentManagementUrl',
getHrsUrl: () => 'hrsUrl',
getRemoteHrsUrl: () => 'remoteHrsUrl',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -15,23 +16,25 @@ describe('DocumentManagementService', () => {

let appConfig: any;
let httpService: any;

let caseNotifier: any;
let documentManagementService: DocumentManagementService;

beforeEach(waitForAsync(() => {
appConfig = createSpyObj<AbstractAppConfig>('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>('caseNotifier', ['caseView']);
httpService = createSpyObj<HttpService>('httpService', ['post']);
documentManagementService = new DocumentManagementService(httpService, appConfig);
caseNotifier.caseView = of({ case_type: { id: 'test' } });
documentManagementService = new DocumentManagementService(httpService, appConfig, caseNotifier);
}));

describe('uploadFile', () => {
Expand Down Expand Up @@ -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>('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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<DocumentData> {
const url = this.getDocStoreUrl();
Expand Down Expand Up @@ -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;
}
}