Allow webhook only on active versions (#11705)

- webhook call should only be allow on active versions
- fixing exceptions that are wrongly sent to sentry
This commit is contained in:
Thomas Trompette
2025-04-23 17:28:41 +02:00
committed by GitHub
parent a2d2db441f
commit 28a1354928
2 changed files with 27 additions and 4 deletions

View File

@ -6,7 +6,10 @@ import { isDefined } from 'twenty-shared/utils';
import { WorkflowTriggerRestApiExceptionFilter } from 'src/engine/core-modules/workflow/filters/workflow-trigger-rest-api-exception.filter';
import { FieldActorSource } from 'src/engine/metadata-modules/field-metadata/composite-types/actor.composite-type';
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
import { WorkflowVersionWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
import {
WorkflowVersionStatus,
WorkflowVersionWorkspaceEntity,
} from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
import { WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';
import {
WorkflowTriggerException,
@ -64,7 +67,7 @@ export class WorkflowTriggerController {
workflow.lastPublishedVersionId === ''
) {
throw new WorkflowTriggerException(
'Workflow not activated',
'Workflow has not been activated',
WorkflowTriggerExceptionCode.INVALID_WORKFLOW_STATUS,
);
}
@ -91,6 +94,13 @@ export class WorkflowTriggerController {
);
}
if (workflowVersion.status !== WorkflowVersionStatus.ACTIVE) {
throw new WorkflowTriggerException(
'Workflow version is not active',
WorkflowTriggerExceptionCode.INVALID_WORKFLOW_STATUS,
);
}
const { workflowRunId } =
await this.workflowTriggerWorkspaceService.runWorkflowVersion({
workflowVersionId: workflow.lastPublishedVersionId,

View File

@ -46,10 +46,17 @@ export class WorkflowTriggerJob {
'workflow',
);
const workflow = await workflowRepository.findOneByOrFail({
const workflow = await workflowRepository.findOneBy({
id: data.workflowId,
});
if (!workflow) {
throw new WorkflowTriggerException(
'Workflow not found',
WorkflowTriggerExceptionCode.NOT_FOUND,
);
}
if (!workflow.lastPublishedVersionId) {
throw new WorkflowTriggerException(
'Workflow has no published version',
@ -62,10 +69,16 @@ export class WorkflowTriggerJob {
'workflowVersion',
);
const workflowVersion = await workflowVersionRepository.findOneByOrFail({
const workflowVersion = await workflowVersionRepository.findOneBy({
id: workflow.lastPublishedVersionId,
});
if (!workflowVersion) {
throw new WorkflowTriggerException(
'Workflow version not found',
WorkflowTriggerExceptionCode.NOT_FOUND,
);
}
if (workflowVersion.status !== WorkflowVersionStatus.ACTIVE) {
throw new WorkflowTriggerException(
'Workflow version is not active',