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:
@ -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 { 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 { FieldActorSource } from 'src/engine/metadata-modules/field-metadata/composite-types/actor.composite-type';
|
||||||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
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 { WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';
|
||||||
import {
|
import {
|
||||||
WorkflowTriggerException,
|
WorkflowTriggerException,
|
||||||
@ -64,7 +67,7 @@ export class WorkflowTriggerController {
|
|||||||
workflow.lastPublishedVersionId === ''
|
workflow.lastPublishedVersionId === ''
|
||||||
) {
|
) {
|
||||||
throw new WorkflowTriggerException(
|
throw new WorkflowTriggerException(
|
||||||
'Workflow not activated',
|
'Workflow has not been activated',
|
||||||
WorkflowTriggerExceptionCode.INVALID_WORKFLOW_STATUS,
|
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 } =
|
const { workflowRunId } =
|
||||||
await this.workflowTriggerWorkspaceService.runWorkflowVersion({
|
await this.workflowTriggerWorkspaceService.runWorkflowVersion({
|
||||||
workflowVersionId: workflow.lastPublishedVersionId,
|
workflowVersionId: workflow.lastPublishedVersionId,
|
||||||
|
|||||||
@ -46,10 +46,17 @@ export class WorkflowTriggerJob {
|
|||||||
'workflow',
|
'workflow',
|
||||||
);
|
);
|
||||||
|
|
||||||
const workflow = await workflowRepository.findOneByOrFail({
|
const workflow = await workflowRepository.findOneBy({
|
||||||
id: data.workflowId,
|
id: data.workflowId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!workflow) {
|
||||||
|
throw new WorkflowTriggerException(
|
||||||
|
'Workflow not found',
|
||||||
|
WorkflowTriggerExceptionCode.NOT_FOUND,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!workflow.lastPublishedVersionId) {
|
if (!workflow.lastPublishedVersionId) {
|
||||||
throw new WorkflowTriggerException(
|
throw new WorkflowTriggerException(
|
||||||
'Workflow has no published version',
|
'Workflow has no published version',
|
||||||
@ -62,10 +69,16 @@ export class WorkflowTriggerJob {
|
|||||||
'workflowVersion',
|
'workflowVersion',
|
||||||
);
|
);
|
||||||
|
|
||||||
const workflowVersion = await workflowVersionRepository.findOneByOrFail({
|
const workflowVersion = await workflowVersionRepository.findOneBy({
|
||||||
id: workflow.lastPublishedVersionId,
|
id: workflow.lastPublishedVersionId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!workflowVersion) {
|
||||||
|
throw new WorkflowTriggerException(
|
||||||
|
'Workflow version not found',
|
||||||
|
WorkflowTriggerExceptionCode.NOT_FOUND,
|
||||||
|
);
|
||||||
|
}
|
||||||
if (workflowVersion.status !== WorkflowVersionStatus.ACTIVE) {
|
if (workflowVersion.status !== WorkflowVersionStatus.ACTIVE) {
|
||||||
throw new WorkflowTriggerException(
|
throw new WorkflowTriggerException(
|
||||||
'Workflow version is not active',
|
'Workflow version is not active',
|
||||||
|
|||||||
Reference in New Issue
Block a user