Fix workflow sub objects updates validation (#12169)

Fixes https://github.com/twentyhq/core-team-issues/issues/983

- Enabling workflow version name update, even if not in draft status
- Assert draft when updating steps
- Enabling workflow run name update
This commit is contained in:
Thomas Trompette
2025-05-21 15:11:32 +02:00
committed by GitHub
parent 23ebd69541
commit 5c16b2752d
3 changed files with 22 additions and 2 deletions
@@ -2,6 +2,7 @@ import { WorkspacePreQueryHookInstance } from 'src/engine/api/graphql/workspace-
import { UpdateOneResolverArgs } from 'src/engine/api/graphql/workspace-resolver-builder/interfaces/workspace-resolvers-builder.interface';
import { WorkspaceQueryHook } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-hook/decorators/workspace-query-hook.decorator';
import { AuthContext } from 'src/engine/core-modules/auth/types/auth-context.type';
import {
WorkflowQueryValidationException,
WorkflowQueryValidationExceptionCode,
@@ -12,7 +13,15 @@ import { WorkflowRunWorkspaceEntity } from 'src/modules/workflow/common/standard
export class WorkflowRunUpdateOnePreQueryHook
implements WorkspacePreQueryHookInstance
{
async execute(): Promise<UpdateOneResolverArgs<WorkflowRunWorkspaceEntity>> {
async execute(
_authContext: AuthContext,
_objectName: string,
payload: UpdateOneResolverArgs<WorkflowRunWorkspaceEntity>,
): Promise<UpdateOneResolverArgs<WorkflowRunWorkspaceEntity>> {
if (Object.keys(payload.data).length === 1 && payload.data.name) {
return payload;
}
throw new WorkflowQueryValidationException(
'Method not allowed.',
WorkflowQueryValidationExceptionCode.FORBIDDEN,
@@ -71,7 +71,11 @@ export class WorkflowVersionValidationWorkspaceService {
payload.id,
);
assertWorkflowVersionIsDraft(workflowVersion);
// If the only field updated is the name, we can update the workflow version
// Otherwise, we need to assert that the workflow version is a draft
if (!(Object.keys(payload.data).length === 1 && payload.data.name)) {
assertWorkflowVersionIsDraft(workflowVersion);
}
if (payload.data.status && payload.data.status !== workflowVersion.status) {
throw new WorkflowQueryValidationException(