forked from twentyhq/twenty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check workflow version is valid before publishing (twentyhq#6702)
Fix twentyhq#6670
- Loading branch information
Showing
4 changed files
with
73 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...ty-server/src/modules/workflow/workflow-trigger/utils/assert-workflow-version-is-valid.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { WorkflowVersionWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity'; | ||
import { | ||
WorkflowTrigger, | ||
WorkflowTriggerType, | ||
} from 'src/modules/workflow/common/types/workflow-trigger.type'; | ||
import { | ||
WorkflowTriggerException, | ||
WorkflowTriggerExceptionCode, | ||
} from 'src/modules/workflow/workflow-trigger/workflow-trigger.exception'; | ||
|
||
export function assertWorkflowVersionIsValid( | ||
workflowVersion: Omit<WorkflowVersionWorkspaceEntity, 'trigger'> & { | ||
trigger: WorkflowTrigger; | ||
}, | ||
) { | ||
if (!workflowVersion.trigger) { | ||
throw new WorkflowTriggerException( | ||
'Workflow version does not contain trigger', | ||
WorkflowTriggerExceptionCode.INVALID_WORKFLOW_VERSION, | ||
); | ||
} | ||
|
||
if (!workflowVersion.trigger.type) { | ||
throw new WorkflowTriggerException( | ||
'No trigger type provided', | ||
WorkflowTriggerExceptionCode.INVALID_WORKFLOW_TRIGGER, | ||
); | ||
} | ||
|
||
if (!workflowVersion.trigger.nextAction) { | ||
throw new WorkflowTriggerException( | ||
'No next action provided in trigger', | ||
WorkflowTriggerExceptionCode.INVALID_WORKFLOW_TRIGGER, | ||
); | ||
} | ||
|
||
assertTriggerSettingsAreValid( | ||
workflowVersion.trigger.type, | ||
workflowVersion.trigger.settings, | ||
); | ||
} | ||
|
||
function assertTriggerSettingsAreValid( | ||
triggerType: WorkflowTriggerType, | ||
settings: any, | ||
) { | ||
switch (triggerType) { | ||
case WorkflowTriggerType.DATABASE_EVENT: | ||
assertDatabaseEventTriggerSettingsAreValid(settings); | ||
break; | ||
default: | ||
throw new WorkflowTriggerException( | ||
'Invalid trigger type for enabling workflow trigger', | ||
WorkflowTriggerExceptionCode.INVALID_WORKFLOW_TRIGGER, | ||
); | ||
} | ||
} | ||
|
||
function assertDatabaseEventTriggerSettingsAreValid(settings: any) { | ||
if (!settings?.eventName) { | ||
throw new WorkflowTriggerException( | ||
'No event name provided in database event trigger', | ||
WorkflowTriggerExceptionCode.INVALID_WORKFLOW_TRIGGER, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters