From cdc75539157d88f665f479e436a6e2395a7dfec4 Mon Sep 17 00:00:00 2001 From: AleksanderSklorz <115619721+AleksanderSklorz@users.noreply.github.com> Date: Thu, 12 Jun 2025 14:21:49 +0200 Subject: [PATCH] [MNT-24923] legal hold hold capabilities are not verified properly (#10930) * [MNT-24923] Added possibility to filter capabilities by person id * [MNT-24923] Documentation and unit tests --- .../api/gs-core-rest-api/api/filePlans.api.ts | 14 +++++--- .../docs/FilePlanRoleParametersWhere.md | 1 + .../model/filePlanRoleParametersWhere.ts | 1 + .../governance-services/filePlansApi.spec.ts | 35 +++++++++++++++++-- .../goverance-services/file-plans.mock.ts | 28 +++++++++++---- 5 files changed, 67 insertions(+), 12 deletions(-) diff --git a/lib/js-api/src/api/gs-core-rest-api/api/filePlans.api.ts b/lib/js-api/src/api/gs-core-rest-api/api/filePlans.api.ts index 00e89bde09..ee34b8231e 100644 --- a/lib/js-api/src/api/gs-core-rest-api/api/filePlans.api.ts +++ b/lib/js-api/src/api/gs-core-rest-api/api/filePlans.api.ts @@ -168,16 +168,22 @@ export class FilePlansApi extends BaseApi { */ getFilePlanRoles(filePlanId: string, parameters?: FilePlanRoleParameters): Promise { throwIfNotDefined(filePlanId, 'filePlanId'); - + const whereConditions: string[] = []; + if (parameters?.where) { + if (parameters.where.personId) { + whereConditions.push(`personId='${parameters.where.personId}'`); + } + if (parameters.where.capabilityNames) { + whereConditions.push(`capabilityName in (${parameters.where.capabilityNames.map((value) => "'" + value + "'").join(', ')})`); + } + } return this.get({ path: '/file-plans/{filePlanId}/roles', pathParams: { filePlanId }, queryParams: { - where: parameters?.where?.capabilityNames - ? `(capabilityName in (${parameters.where.capabilityNames.map((value) => "'" + value + "'").join(', ')}))` - : undefined + where: whereConditions.length ? `(${whereConditions.join(' and ')})` : undefined } }); } diff --git a/lib/js-api/src/api/gs-core-rest-api/docs/FilePlanRoleParametersWhere.md b/lib/js-api/src/api/gs-core-rest-api/docs/FilePlanRoleParametersWhere.md index 95b50cad52..c06ad325a7 100644 --- a/lib/js-api/src/api/gs-core-rest-api/docs/FilePlanRoleParametersWhere.md +++ b/lib/js-api/src/api/gs-core-rest-api/docs/FilePlanRoleParametersWhere.md @@ -3,6 +3,7 @@ ## Properties | Name | Type | |---------------------|----------| +| **personId** | string | | **capabilityNames** | string[] | diff --git a/lib/js-api/src/api/gs-core-rest-api/model/filePlanRoleParametersWhere.ts b/lib/js-api/src/api/gs-core-rest-api/model/filePlanRoleParametersWhere.ts index c0c81553c3..5cc6139640 100644 --- a/lib/js-api/src/api/gs-core-rest-api/model/filePlanRoleParametersWhere.ts +++ b/lib/js-api/src/api/gs-core-rest-api/model/filePlanRoleParametersWhere.ts @@ -16,5 +16,6 @@ */ export interface FilePlanRoleParametersWhere { + personId?: string; capabilityNames?: string[]; } diff --git a/lib/js-api/test/governance-services/filePlansApi.spec.ts b/lib/js-api/test/governance-services/filePlansApi.spec.ts index c48788ea65..35503d3418 100644 --- a/lib/js-api/test/governance-services/filePlansApi.spec.ts +++ b/lib/js-api/test/governance-services/filePlansApi.spec.ts @@ -35,6 +35,8 @@ describe('FilePlansApi', () => { }); describe('getFilePlanRoles', () => { + const filePlanId = 'filePlanId123'; + let expectedRolePaging: FilePlanRolePaging; beforeEach(() => { @@ -101,7 +103,6 @@ describe('FilePlansApi', () => { }); it('should get file plan roles', (done) => { - const filePlanId = 'filePlanId123'; filePlansApiMock.get200FilePlanRoles(filePlanId); filePlansApi.getFilePlanRoles(filePlanId).then((rolePaging) => { @@ -111,7 +112,6 @@ describe('FilePlansApi', () => { }); it('should get file plan roles with filtering by capability names', (done) => { - const filePlanId = 'filePlanId123'; filePlansApiMock.get200FilePlanRolesWithFilteringByCapabilityNames(filePlanId); filePlansApi @@ -125,5 +125,36 @@ describe('FilePlansApi', () => { done(); }); }); + + it('should get file plan roles with filtering by person id', (done) => { + filePlansApiMock.get200FilePlanRolesWithFilteringByPersonId(filePlanId); + + filePlansApi + .getFilePlanRoles(filePlanId, { + where: { + personId: 'someUser' + } + }) + .then((rolePaging) => { + expect(rolePaging).toEqual(expectedRolePaging); + done(); + }); + }); + + it('should get file plan roles with filtering by capability names', (done) => { + filePlansApiMock.get200FilePlanRolesWithFilteringByPersonIdAndCapabilityNames(filePlanId); + + filePlansApi + .getFilePlanRoles(filePlanId, { + where: { + personId: 'someUser', + capabilityNames: ['capability1', 'capability2'] + } + }) + .then((rolePaging) => { + expect(rolePaging).toEqual(expectedRolePaging); + done(); + }); + }); }); }); diff --git a/lib/js-api/test/mockObjects/goverance-services/file-plans.mock.ts b/lib/js-api/test/mockObjects/goverance-services/file-plans.mock.ts index bdaf094e07..64e4997b93 100644 --- a/lib/js-api/test/mockObjects/goverance-services/file-plans.mock.ts +++ b/lib/js-api/test/mockObjects/goverance-services/file-plans.mock.ts @@ -21,21 +21,37 @@ import { FilePlanRolePaging } from '@alfresco/js-api'; export class FilePlansMock extends BaseMock { get200FilePlanRoles(filePlanId: string): void { - nock(this.host, { encodedQueryParams: true }) - .get(`/alfresco/api/-default-/public/gs/versions/1/file-plans/${filePlanId}/roles`) - .query({}) - .reply(200, this.mockFilePlanRolePaging()); + this.nock200FilePlanRoles(filePlanId).query({}).reply(200, this.mockFilePlanRolePaging()); } get200FilePlanRolesWithFilteringByCapabilityNames(filePlanId: string): void { - nock(this.host, { encodedQueryParams: true }) - .get(`/alfresco/api/-default-/public/gs/versions/1/file-plans/${filePlanId}/roles`) + this.nock200FilePlanRoles(filePlanId) .query({ where: "(capabilityName in ('capability1', 'capability2'))" }) .reply(200, this.mockFilePlanRolePaging()); } + get200FilePlanRolesWithFilteringByPersonId(filePlanId: string): void { + this.nock200FilePlanRoles(filePlanId) + .query({ + where: "(personId='someUser')" + }) + .reply(200, this.mockFilePlanRolePaging()); + } + + get200FilePlanRolesWithFilteringByPersonIdAndCapabilityNames(filePlanId: string): void { + this.nock200FilePlanRoles(filePlanId) + .query({ + where: "(personId='someUser' and capabilityName in ('capability1', 'capability2'))" + }) + .reply(200, this.mockFilePlanRolePaging()); + } + + private nock200FilePlanRoles(filePlanId: string): nock.Interceptor { + return nock(this.host, { encodedQueryParams: true }).get(`/alfresco/api/-default-/public/gs/versions/1/file-plans/${filePlanId}/roles`); + } + private mockFilePlanRolePaging(): FilePlanRolePaging { return { list: {