Skip to content

Commit

Permalink
fix: analysis-node update operation
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Nov 6, 2024
1 parent 5645217 commit ba6cc10
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -70,26 +67,35 @@ 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.',
);
}
}

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.',
);
}
}
Expand Down

0 comments on commit ba6cc10

Please sign in to comment.