Skip to content

The open alternative to Salesforce, designed for AI.

Keep email and calendar steps out of application workflows (#27072)

Thomas Trompette2c68f8f7f85e
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-workflow-step-manifest-to-action-or-throw.util.spec.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-workflow-step-manifest-to-action-or-throw.util.spec.ts
index 7f2e19c827c..53d9531d158 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-workflow-step-manifest-to-action-or-throw.util.spec.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-workflow-step-manifest-to-action-or-throw.util.spec.ts
@@ -46,10 +46,6 @@ const record = {
objectUniversalIdentifier: REFERENCE_ID,
objectRecord: { name: 'Company' },
};
-const email = {
- connectedAccountId: '{{trigger.accountId}}',
- recipients: { to: '[email protected]' },
-};
const filters = { stepFilterGroups: [], stepFilters: [] };
const inputs = {
LOGIC_FUNCTION: { value: 'Hello' },
@@ -90,17 +86,6 @@ const inputs = {
fieldUniversalIdentifier: FIELD_ID,
},
},
- SEND_EMAIL: email,
- DRAFT_EMAIL: email,
- CREATE_CALENDAR_EVENT: {
- connectedAccountId: '{{trigger.accountId}}',
- title: 'Meeting',
- startsAt: '2026-10-01T10:00:00Z',
- endsAt: '2026-10-01T11:00:00Z',
- isFullDay: false,
- sendInvitations: false,
- addConferencing: false,
- },
FORM: [
{
id: FIELD_ID,
@@ -191,6 +176,9 @@ describe('application workflow actions', () => {
Object.values(WorkflowActionType).filter(
(type) =>
type !== WorkflowActionType.CODE &&
+ type !== WorkflowActionType.SEND_EMAIL &&
+ type !== WorkflowActionType.DRAFT_EMAIL &&
+ type !== WorkflowActionType.CREATE_CALENDAR_EVENT &&
type !== WorkflowActionType.SEND_CHAT_MESSAGE,
),
)('converts %s to its runtime action', (type) => {
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/assert-step-type-available-to-application-run.util.spec.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/assert-step-type-available-to-application-run.util.spec.ts
new file mode 100644
index 00000000000..87ffbef9a78
--- /dev/null
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/assert-step-type-available-to-application-run.util.spec.ts
@@ -0,0 +1,36 @@
+import { WorkflowActionType } from 'twenty-shared/workflow';
+
+import { assertStepTypeAvailableToApplicationRun } from 'src/modules/workflow/workflow-executor/utils/assert-step-type-available-to-application-run.util';
+
+describe('assertStepTypeAvailableToApplicationRun', () => {
+ it.each([
+ WorkflowActionType.SEND_EMAIL,
+ WorkflowActionType.DRAFT_EMAIL,
+ WorkflowActionType.CREATE_CALENDAR_EVENT,
+ ])('refuses %s steps in a run started by an application', (stepType) => {
+ expect(() =>
+ assertStepTypeAvailableToApplicationRun({
+ stepType,
+ runApplicationId: 'installed-app-id',
+ }),
+ ).toThrow(`Applications cannot use ${stepType} steps`);
+ });
+
+ it('lets a run started by an application use other steps', () => {
+ expect(() =>
+ assertStepTypeAvailableToApplicationRun({
+ stepType: WorkflowActionType.CREATE_RECORD,
+ runApplicationId: 'installed-app-id',
+ }),
+ ).not.toThrow();
+ });
+
+ it('lets a run without an application send emails', () => {
+ expect(() =>
+ assertStepTypeAvailableToApplicationRun({
+ stepType: WorkflowActionType.SEND_EMAIL,
+ runApplicationId: undefined,
+ }),
+ ).not.toThrow();
+ });
+});
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/assert-step-type-available-to-application-run.util.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/assert-step-type-available-to-application-run.util.ts
new file mode 100644
index 00000000000..9813588c8a4
--- /dev/null
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/assert-step-type-available-to-application-run.util.ts
@@ -0,0 +1,28 @@
+import { APPLICATION_WORKFLOW_UNAVAILABLE_STEP_TYPES } from 'twenty-shared/application';
+import { isDefined } from 'twenty-shared/utils';
+import { type WorkflowActionType } from 'twenty-shared/workflow';
+
+import {
+ WorkflowStepExecutorException,
+ WorkflowStepExecutorExceptionCode,
+} from 'src/modules/workflow/workflow-executor/exceptions/workflow-step-executor.exception';
+
+export const assertStepTypeAvailableToApplicationRun = ({
+ stepType,
+ runApplicationId,
+}: {
+ stepType: WorkflowActionType;
+ runApplicationId?: string;
+}): void => {
+ if (
+ !isDefined(runApplicationId) ||
+ !APPLICATION_WORKFLOW_UNAVAILABLE_STEP_TYPES.includes(stepType)
+ ) {
+ return;
+ }
+
+ throw new WorkflowStepExecutorException(
+ `Applications cannot use ${stepType} steps`,
+ WorkflowStepExecutorExceptionCode.FORBIDDEN,
+ );
+};
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workspace-services/workflow-executor.workspace-service.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workspace-services/workflow-executor.workspace-service.ts
index 9c7dbc9ddea..771a8ac4069 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-executor/workspace-services/workflow-executor.workspace-service.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workspace-services/workflow-executor.workspace-service.ts
@@ -39,6 +39,7 @@ import {
type WorkflowBranchExecutorInput,
type WorkflowExecutorInput,
} from 'src/modules/workflow/workflow-executor/types/workflow-executor-input.type';
+import { assertStepTypeAvailableToApplicationRun } from 'src/modules/workflow/workflow-executor/utils/assert-step-type-available-to-application-run.util';
import { getStepRetryDelayMs } from 'src/modules/workflow/workflow-executor/utils/get-step-retry-delay-ms.util';
import { isUserFacingWorkflowExecutorError } from 'src/modules/workflow/workflow-executor/utils/is-user-facing-workflow-executor-error.util';
import { stepHasRetryAttemptsLeft } from 'src/modules/workflow/workflow-executor/utils/step-has-retry-attempts-left.util';
@@ -178,6 +179,7 @@ export class WorkflowExecutorWorkspaceService {
workflowRunId,
workspaceId,
billingSpenders,
+ runApplicationId: workflowRun.createdBy.context?.applicationId,
resumedThreadId,
previousStepLog: isDefined(resumedThreadId)
? workflowRun.stepLogs?.[stepId]
@@ -547,6 +549,7 @@ export class WorkflowExecutorWorkspaceService {
workflowRunId,
workspaceId,
billingSpenders,
+ runApplicationId,
resumedThreadId,
previousStepLog,
}: {
@@ -556,6 +559,7 @@ export class WorkflowExecutorWorkspaceService {
workflowRunId: string;
workspaceId: string;
billingSpenders: WorkflowBillingSpenders;
+ runApplicationId?: string;
resumedThreadId?: string;
previousStepLog?: WorkflowRunStepLog;
}) {
@@ -576,6 +580,11 @@ export class WorkflowExecutorWorkspaceService {
try {
await this.assertActionTypeEnabled({ type: step.type, workspaceId });
+ assertStepTypeAvailableToApplicationRun({
+ stepType: step.type,
+ runApplicationId,
+ });
+
// A resumed step's quota was checked when it first ran and paused.
const nodeRunRefusal = isDefined(resumedThreadId)
? undefined
diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/application-workflow-execution-permissions.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/application-workflow-execution-permissions.integration-spec.ts
index e282dd30498..0e8301020d1 100644
--- a/packages/twenty-server/test/integration/graphql/suites/workflow/application-workflow-execution-permissions.integration-spec.ts
+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/application-workflow-execution-permissions.integration-spec.ts
@@ -552,6 +552,23 @@ describe('application workflow execution permissions', () => {
).toBe(0);
}, 120000);
+ it('refuses email steps when an application token starts a workspace workflow', async () => {
+ const { status, stepStatus, stepError } = await runWorkflowActionStep({
+ name: `${RUN_PREFIX} workspace email workflow started by the application`,
+ stepType: 'SEND_EMAIL',
+ input: {
+ recipients: { to: '[email protected]' },
+ subject: 'Application workflow permissions',
+ body: 'Should never be sent',
+ },
+ runToken: await buildJaneTokenThroughApplication(APP_ID),
+ });
+
+ expect(status).toBe('FAILED');
+ expect(stepStatus).toBe('FAILED');
+ expect(stepError).toContain('Applications cannot use SEND_EMAIL steps');
+ }, 120000);
+
it('only lets the values of a form step change on an application workflow run', async () => {
const workflowRunId = await runWorkflow(FORM_WORKFLOW);
const [formStep] = FORM_WORKFLOW.steps;
diff --git a/packages/twenty-shared/src/application/__tests__/workflowManifestType.spec.ts b/packages/twenty-shared/src/application/__tests__/workflowManifestType.spec.ts
index 7c74b6e9bdd..38a57b0da0b 100644
--- a/packages/twenty-shared/src/application/__tests__/workflowManifestType.spec.ts
+++ b/packages/twenty-shared/src/application/__tests__/workflowManifestType.spec.ts
@@ -1,5 +1,6 @@
/** @jest-environment node */
+import { APPLICATION_WORKFLOW_UNAVAILABLE_STEP_TYPES } from '@/application/constants/ApplicationWorkflowUnavailableStepTypes';
import { isDefined } from '@/utils/validation/isDefined';
import {
@@ -121,3 +122,21 @@ describe('workflow manifest iterator cycles', () => {
expect(workflowManifestSchema.safeParse(invalid).success).toBe(false);
});
});
+
+describe('workflow manifest step types', () => {
+ it.each(APPLICATION_WORKFLOW_UNAVAILABLE_STEP_TYPES)(
+ 'rejects %s steps',
+ (type) => {
+ const invalid = structuredClone(workflow);
+ Object.assign(getStep(invalid, 2), { type });
+ const result = workflowManifestSchema.safeParse(invalid);
+ expect(result.success).toBe(false);
+ expect(result.error?.issues[0]?.path).toEqual([
+ 'version',
+ 'steps',
+ 2,
+ 'type',
+ ]);
+ },
+ );
+});
diff --git a/packages/twenty-shared/src/application/constants/ApplicationWorkflowUnavailableStepTypes.ts b/packages/twenty-shared/src/application/constants/ApplicationWorkflowUnavailableStepTypes.ts
new file mode 100644
index 00000000000..1d54a362f7e
--- /dev/null
+++ b/packages/twenty-shared/src/application/constants/ApplicationWorkflowUnavailableStepTypes.ts
@@ -0,0 +1,8 @@
+import { WorkflowActionType } from '@/workflow/types/WorkflowActionType';
+
+export const APPLICATION_WORKFLOW_UNAVAILABLE_STEP_TYPES: readonly WorkflowActionType[] =
+ [
+ WorkflowActionType.SEND_EMAIL,
+ WorkflowActionType.DRAFT_EMAIL,
+ WorkflowActionType.CREATE_CALENDAR_EVENT,
+ ];
diff --git a/packages/twenty-shared/src/application/index.ts b/packages/twenty-shared/src/application/index.ts
index fd285509693..284f873b439 100644
--- a/packages/twenty-shared/src/application/index.ts
+++ b/packages/twenty-shared/src/application/index.ts
@@ -67,6 +67,7 @@ export type {
export type { ConnectionProviderManifest } from './connectionProviderManifestType';
export type { ConnectionProviderType } from './connectionProviderType';
export { APPLICATION_FILE_UPLOAD_BATCH_SIZE } from './constants/ApplicationFileUploadBatchSize';
+export { APPLICATION_WORKFLOW_UNAVAILABLE_STEP_TYPES } from './constants/ApplicationWorkflowUnavailableStepTypes';
export { ASSETS_DIR } from './constants/AssetDirectory';
export { DEFAULT_API_KEY_NAME } from './constants/DefaultApiKeyName';
export { DEFAULT_API_URL_NAME } from './constants/DefaultApiUrlName';
diff --git a/packages/twenty-shared/src/application/workflowStepManifestType.ts b/packages/twenty-shared/src/application/workflowStepManifestType.ts
index 30dae3e8b5d..6bc48fbcc0f 100644
--- a/packages/twenty-shared/src/application/workflowStepManifestType.ts
+++ b/packages/twenty-shared/src/application/workflowStepManifestType.ts
@@ -2,8 +2,6 @@ import { z } from 'zod';
import { isDefined } from '@/utils/validation/isDefined';
-import { workflowSendEmailActionSettingsSchema } from '@/workflow/schemas/send-email-action-settings-schema';
-import { workflowCreateCalendarEventActionSettingsSchema } from '@/workflow/schemas/create-calendar-event-action-settings-schema';
import { workflowHttpRequestActionSettingsSchema } from '@/workflow/schemas/http-request-action-settings-schema';
import { workflowClassifyActionSettingsSchema } from '@/workflow/schemas/classify-action-settings-schema';
import { workflowIteratorActionSettingsSchema } from '@/workflow/schemas/iterator-action-settings-schema';
@@ -56,11 +54,6 @@ export const workflowStepManifestSchema = z.discriminatedUnion('type', [
logicFunctionUniversalIdentifier: z.uuid(),
input: z.record(z.string(), z.unknown()),
}),
- stepSchema('SEND_EMAIL', workflowSendEmailActionSettingsSchema.shape.input),
- stepSchema(
- 'CREATE_CALENDAR_EVENT',
- workflowCreateCalendarEventActionSettingsSchema.shape.input,
- ),
stepSchema(
'HTTP_REQUEST',
workflowHttpRequestActionSettingsSchema.shape.input,
@@ -69,7 +62,6 @@ export const workflowStepManifestSchema = z.discriminatedUnion('type', [
stepSchema('ITERATOR', workflowIteratorActionSettingsSchema.shape.input),
stepSchema('DELAY', workflowDelayActionSettingsSchema.shape.input),
stepSchema('EMPTY', workflowEmptyActionSettingsSchema.shape.input),
- stepSchema('DRAFT_EMAIL', workflowSendEmailActionSettingsSchema.shape.input),
stepSchema(
'CREATE_RECORD',
workflowCreateRecordActionSettingsSchema.shape.input