From e9c6c642900b3da1870c0037fde78eebad9d4be4 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Sat, 21 Mar 2020 00:30:03 +0100 Subject: [PATCH] :bug: Fix bug that not all webhooks got deleted when active & testing #387 --- packages/cli/src/Server.ts | 11 +---------- packages/cli/src/TestWebhooks.ts | 17 +++++++++++------ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index 0f99ee8500..2f539c6f5c 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -1099,16 +1099,7 @@ class App { // Removes a test webhook this.app.delete('/rest/test-webhook/:id', ResponseHelper.send(async (req: express.Request, res: express.Response): Promise => { const workflowId = req.params.id; - - const workflowData = await Db.collections.Workflow!.findOne(workflowId); - if (workflowData === undefined) { - throw new ResponseHelper.ResponseError(`Could not find workflow with id "${workflowId}" so webhook could not be deleted!`); - } - - const nodeTypes = NodeTypes(); - const workflow = new Workflow({ id: workflowId.toString(), name: workflowData.name, nodes: workflowData.nodes, connections: workflowData.connections, active: workflowData.active, nodeTypes, staticData: workflowData.staticData, settings: workflowData.settings }); - - return this.testWebhooks.cancelTestWebhook(workflowId, workflow); + return this.testWebhooks.cancelTestWebhook(workflowId); })); diff --git a/packages/cli/src/TestWebhooks.ts b/packages/cli/src/TestWebhooks.ts index 8aac38c9c6..aa6dd1d163 100644 --- a/packages/cli/src/TestWebhooks.ts +++ b/packages/cli/src/TestWebhooks.ts @@ -131,7 +131,7 @@ export class TestWebhooks { // Remove test-webhooks automatically if they do not get called (after 120 seconds) const timeout = setTimeout(() => { - this.cancelTestWebhook(workflowData.id.toString(), workflow); + this.cancelTestWebhook(workflowData.id.toString()); }, 120000); let key: string; @@ -143,10 +143,10 @@ export class TestWebhooks { workflowData, }; await this.activeWebhooks!.add(workflow, webhookData, mode); - } - // Save static data! - await WorkflowHelpers.saveStaticData(workflow); + // Save static data! + this.testWebhookData[key].workflowData.staticData = workflow.staticData; + } return true; } @@ -159,7 +159,9 @@ export class TestWebhooks { * @returns {boolean} * @memberof TestWebhooks */ - cancelTestWebhook(workflowId: string, workflow: Workflow): boolean { + cancelTestWebhook(workflowId: string): boolean { + const nodeTypes = NodeTypes(); + let foundWebhook = false; for (const webhookKey of Object.keys(this.testWebhookData)) { const webhookData = this.testWebhookData[webhookKey]; @@ -182,6 +184,9 @@ export class TestWebhooks { } } + const workflowData = webhookData.workflowData; + const workflow = new Workflow({ id: workflowData.id.toString(), name: workflowData.name, nodes: workflowData.nodes, connections: workflowData.connections, active: workflowData.active, nodeTypes, staticData: workflowData.staticData, settings: workflowData.settings }); + // Remove the webhook delete this.testWebhookData[webhookKey]; this.activeWebhooks!.removeWorkflow(workflow); @@ -207,7 +212,7 @@ export class TestWebhooks { for (const webhookKey of Object.keys(this.testWebhookData)) { workflowData = this.testWebhookData[webhookKey].workflowData; workflow = new Workflow({ id: workflowData.id.toString(), name: workflowData.name, nodes: workflowData.nodes, connections: workflowData.connections, active: workflowData.active, nodeTypes, staticData: workflowData.staticData, settings: workflowData.settings }); - workflows.push(); + workflows.push(workflow); } return this.activeWebhooks.removeAll(workflows);