fix(API): Do not add starting node on workflow creation (#6686)

* fix(API): Do not add starting node on workflow creation

* chore: Remove comment
This commit is contained in:
Iván Ovejero 2023-07-18 14:03:19 +02:00 committed by GitHub
parent 2a6cd26def
commit 92192fbd61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 38 deletions

View file

@ -64,7 +64,7 @@ import { WorkflowRunner } from '@/WorkflowRunner';
import { ExternalHooks } from '@/ExternalHooks';
import { whereClause } from './UserManagement/UserManagementHelper';
import { WorkflowsService } from './workflows/workflows.services';
import { START_NODES } from './constants';
import { STARTING_NODES } from './constants';
import { webhookNotFoundErrorMessage } from './utils';
import { In } from 'typeorm';
@ -793,7 +793,7 @@ export class ActiveWorkflowRunner {
settings: workflowData.settings,
});
const canBeActivated = workflowInstance.checkIfWorkflowCanBeActivated(START_NODES);
const canBeActivated = workflowInstance.checkIfWorkflowCanBeActivated(STARTING_NODES);
if (!canBeActivated) {
Logger.error(`Unable to activate workflow "${workflowData.name}"`);
throw new Error(

View file

@ -18,8 +18,6 @@ import {
setWorkflowAsActive,
setWorkflowAsInactive,
updateWorkflow,
hasStartNode,
getStartNode,
getSharedWorkflows,
createWorkflow,
getWorkflowIdsViaTags,
@ -37,10 +35,6 @@ export = {
workflow.active = false;
if (!hasStartNode(workflow)) {
workflow.nodes.push(getStartNode());
}
await replaceInvalidCredentials(workflow);
addNodeIds(workflow);
@ -164,10 +158,6 @@ export = {
return res.status(404).json({ message: 'Not Found' });
}
if (!hasStartNode(updateData)) {
updateData.nodes.push(getStartNode());
}
await replaceInvalidCredentials(updateData);
addNodeIds(updateData);

View file

@ -1,8 +1,6 @@
import type { FindManyOptions, UpdateResult } from 'typeorm';
import { In } from 'typeorm';
import intersection from 'lodash/intersection';
import type { INode } from 'n8n-workflow';
import { v4 as uuid } from 'uuid';
import * as Db from '@/Db';
import type { User } from '@db/entities/User';
@ -10,7 +8,6 @@ import { WorkflowEntity } from '@db/entities/WorkflowEntity';
import { SharedWorkflow } from '@db/entities/SharedWorkflow';
import type { Role } from '@db/entities/Role';
import config from '@/config';
import { START_NODES } from '@/constants';
function insertIf(condition: boolean, elements: string[]): string[] {
return condition ? elements : [];
@ -122,25 +119,6 @@ export async function updateWorkflow(
return Db.collections.Workflow.update(workflowId, updateData);
}
export function hasStartNode(workflow: WorkflowEntity): boolean {
if (!workflow.nodes.length) return false;
const found = workflow.nodes.find((node) => START_NODES.includes(node.type));
return Boolean(found);
}
export function getStartNode(): INode {
return {
id: uuid(),
parameters: {},
name: 'Start',
type: 'n8n-nodes-base.start',
typeVersion: 1,
position: [240, 300],
};
}
export function parseTagNames(tags: string): string[] {
return tags.split(',').map((tag) => tag.trim());
}

View file

@ -9,7 +9,7 @@ info:
license:
name: Sustainable Use License
url: https://github.com/n8n-io/n8n/blob/master/packages/cli/LICENSE.md
version: 1.1.0
version: 1.1.1
externalDocs:
description: n8n API documentation
url: https://docs.n8n.io/api/

View file

@ -26,7 +26,7 @@ export function getN8nPackageJson() {
return jsonParse<n8n.PackageJson>(readFileSync(join(CLI_DIR, 'package.json'), 'utf8'));
}
export const START_NODES = ['n8n-nodes-base.start', 'n8n-nodes-base.manualTrigger'];
export const STARTING_NODES = ['n8n-nodes-base.start', 'n8n-nodes-base.manualTrigger'];
export const N8N_VERSION = getN8nPackageJson().version;

View file

@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { CliWorkflowOperationError, SubworkflowOperationError } from 'n8n-workflow';
import type { INode } from 'n8n-workflow';
import { START_NODES } from './constants';
import { STARTING_NODES } from './constants';
/**
* Returns if the given id is a valid workflow id
@ -19,7 +19,7 @@ function findWorkflowStart(executionMode: 'integrated' | 'cli') {
if (executeWorkflowTriggerNode) return executeWorkflowTriggerNode;
const startNode = nodes.find((node) => START_NODES.includes(node.type));
const startNode = nodes.find((node) => STARTING_NODES.includes(node.type));
if (startNode) return startNode;

View file

@ -8,6 +8,8 @@ import type { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
import { randomApiKey } from '../shared/random';
import * as utils from '../shared/utils/';
import * as testDb from '../shared/testDb';
import type { INode } from 'n8n-workflow';
import { STARTING_NODES } from '@/constants';
let workflowOwnerRole: Role;
let owner: User;
@ -676,6 +678,35 @@ describe('POST /workflows', () => {
expect(sharedWorkflow?.workflow.createdAt.toISOString()).toBe(createdAt);
expect(sharedWorkflow?.role).toEqual(workflowOwnerRole);
});
test('should not add a starting node if the payload has no starting nodes', async () => {
const response = await authMemberAgent.post('/workflows').send({
name: 'testing',
nodes: [
{
id: 'uuid-1234',
parameters: {},
name: 'Hacker News',
type: 'n8n-nodes-base.hackerNews',
typeVersion: 1,
position: [240, 300],
},
],
connections: {},
settings: {
saveExecutionProgress: true,
saveManualExecutions: true,
saveDataErrorExecution: 'all',
saveDataSuccessExecution: 'all',
executionTimeout: 3600,
timezone: 'America/New_York',
},
});
const found = response.body.nodes.find((node: INode) => STARTING_NODES.includes(node.type));
expect(found).toBeUndefined();
});
});
describe('PUT /workflows/:id', () => {