From 1d67fa1424d3079540ac297b6899b03966e406d9 Mon Sep 17 00:00:00 2001 From: tada5hi Date: Mon, 1 Jul 2024 14:03:09 +0200 Subject: [PATCH] fix: read analysis-permission read handler --- .../controllers/core/analysis-permission/handlers/read.ts | 6 ++++-- .../core/analysis-permission/utils/validation.ts | 6 ++++++ .../server-core/test/unit/http/analysis-permission.spec.ts | 4 ++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/server-core/src/http/controllers/core/analysis-permission/handlers/read.ts b/packages/server-core/src/http/controllers/core/analysis-permission/handlers/read.ts index d1097e2ce..116803d30 100644 --- a/packages/server-core/src/http/controllers/core/analysis-permission/handlers/read.ts +++ b/packages/server-core/src/http/controllers/core/analysis-permission/handlers/read.ts @@ -57,6 +57,7 @@ export async function getOneAnalysisPermissionRouteHandler(req: Request, res: Re .where('analysisPermission.id = :id', { id }); const relationsMap = getRelations(req); + if (relationsMap.analysis) { applyQueryRelationsParseOutput(query, [ relationsMap.analysis, @@ -78,8 +79,9 @@ export async function getOneAnalysisPermissionRouteHandler(req: Request, res: Re } if (relationsMap.policy) { - // todo: enable when policy api client is defined - // entity.policy = await authupClient.policy.getOne(entity.policy_id); + if (entity.policy_id) { + entity.policy = await authupClient.policy.getOne(entity.policy_id); + } } } diff --git a/packages/server-core/src/http/controllers/core/analysis-permission/utils/validation.ts b/packages/server-core/src/http/controllers/core/analysis-permission/utils/validation.ts index dbca1209b..66b05914b 100644 --- a/packages/server-core/src/http/controllers/core/analysis-permission/utils/validation.ts +++ b/packages/server-core/src/http/controllers/core/analysis-permission/utils/validation.ts @@ -72,6 +72,9 @@ export async function runAnalysisPermissionValidation( result.data.permission = permission; result.data.permission_realm_id = permission.realm_id; + + // todo: remove this when validation is reworked. + result.relation.permission = permission; } catch (e) { if (isClientErrorWithStatusCode(e, 404)) { throw new BadRequestError(buildHTTPValidationErrorMessage('permission_id')); @@ -95,6 +98,9 @@ export async function runAnalysisPermissionValidation( result.data.policy = policy; result.data.policy_id = policy.id; + + // todo: remove this when validation is reworked. + result.relation.policy = policy; } catch (e) { if (isClientErrorWithStatusCode(e, 404)) { throw new BadRequestError(buildHTTPValidationErrorMessage('permission_id')); diff --git a/packages/server-core/test/unit/http/analysis-permission.spec.ts b/packages/server-core/test/unit/http/analysis-permission.spec.ts index 7fcf39eb1..ad238962a 100644 --- a/packages/server-core/test/unit/http/analysis-permission.spec.ts +++ b/packages/server-core/test/unit/http/analysis-permission.spec.ts @@ -55,6 +55,10 @@ describe('src/controllers/core/analysis-permission', () => { } const analysisPermission = await client.analysisPermission.create(attributes); + + delete analysisPermission.analysis; + delete analysisPermission.permission; + extendObject(attributes, removeDateProperties(analysisPermission)); });