From ba6cc10c99688ca25eecd4c06242dcea60b8281c Mon Sep 17 00:00:00 2001 From: tada5hi Date: Wed, 6 Nov 2024 15:15:06 +0100 Subject: [PATCH] fix: analysis-node update operation --- .../analysis-node/handlers/update.ts | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/server-core/src/http/controllers/analysis-node/handlers/update.ts b/packages/server-core/src/http/controllers/analysis-node/handlers/update.ts index 67e6dd465..9eb89bb2b 100644 --- a/packages/server-core/src/http/controllers/analysis-node/handlers/update.ts +++ b/packages/server-core/src/http/controllers/analysis-node/handlers/update.ts @@ -5,6 +5,7 @@ * view the LICENSE file that was distributed with this source code. */ +import { isPropertySet } from '@authup/kit'; import { BadRequestError, ForbiddenError, NotFoundError } from '@ebec/http'; import { isRealmResourceWritable } from '@authup/core-kit'; import { PermissionName } from '@privateaim/kit'; @@ -38,10 +39,6 @@ export async function updateAnalysisNodeRouteHandler(req: Request, res: Response throw new NotFoundError(); } - if (entity.analysis.configuration_locked) { - throw new BadRequestError('The analysis is locked right now. It is not possible to add new nodes.'); - } - const isAuthorityOfNode = isRealmResourceWritable(useRequestIdentityRealm(req), entity.node_realm_id); const isAuthorityOfAnalysis = isRealmResourceWritable(useRequestIdentityRealm(req), entity.analysis_realm_id); @@ -70,18 +67,27 @@ export async function updateAnalysisNodeRouteHandler(req: Request, res: Response throw new ForbiddenError(); } - if (!isAuthorityOfNode || !canApprove) { - if (data.approval_status || data.comment) { + if ( + isPropertySet(data, 'approval_status') || + isPropertySet(data, 'comment') + ) { + if (!isAuthorityOfNode || !canApprove) { throw new BadRequestError( - 'You are either no authority of the node or you don\'t have the required permissions', + 'You are either no authority of the node or you don\'t have the required permissions.', ); } } + if (isPropertySet(data, 'approval_status')) { + if (entity.analysis.configuration_locked) { + throw new BadRequestError('The analysis is locked right now. It is not possible to add new nodes.'); + } + } + if (!isAuthorityOfNode || !canUpdate) { if (data.run_status) { throw new BadRequestError( - 'You are either no authority of the node or you don\'t have the required permissions', + 'You are either no authority of the node or you don\'t have the required permissions.', ); } } @@ -89,7 +95,7 @@ export async function updateAnalysisNodeRouteHandler(req: Request, res: Response if (!isAuthorityOfAnalysis || !canUpdate) { if (data.index) { throw new BadRequestError( - 'You are either no authority of the analysis or you don\'t have the required permissions', + 'You are either no authority of the analysis or you don\'t have the required permissions.', ); } }