From 85dcb28375e677c29c2651a79ae02a4aae68a383 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 18 Sep 2020 14:34:14 +0100 Subject: [PATCH] Fixing an issue where inputs from the builder send empty string when realistically it means no input. --- .../server/src/api/controllers/workflow.js | 26 +++++++++++++++++-- .../server/src/workflows/steps/sendEmail.js | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/server/src/api/controllers/workflow.js b/packages/server/src/api/controllers/workflow.js index 04a0b7f1ba..443fc9e378 100644 --- a/packages/server/src/api/controllers/workflow.js +++ b/packages/server/src/api/controllers/workflow.js @@ -10,13 +10,34 @@ const triggers = require("../../workflows/triggers") * * *************************/ +function cleanWorkflowInputs(workflow) { + if (workflow == null) { + return workflow + } + let steps = workflow.definition.steps + let trigger = workflow.definition.trigger + let allSteps = [...steps, trigger] + for (let step of allSteps) { + if (step == null) { + continue + } + for (let inputName of Object.keys(step.inputs)) { + if (!step.inputs[inputName] || step.inputs[inputName] === "") { + delete step.inputs[inputName] + } + } + } + return workflow +} + exports.create = async function(ctx) { const db = new CouchDB(ctx.user.instanceId) - const workflow = ctx.request.body + let workflow = ctx.request.body workflow._id = newid() workflow.type = "workflow" + workflow = cleanWorkflowInputs(workflow) const response = await db.post(workflow) workflow._rev = response.rev @@ -32,8 +53,9 @@ exports.create = async function(ctx) { exports.update = async function(ctx) { const db = new CouchDB(ctx.user.instanceId) - const workflow = ctx.request.body + let workflow = ctx.request.body + workflow = cleanWorkflowInputs(workflow) const response = await db.put(workflow) workflow._rev = response.rev diff --git a/packages/server/src/workflows/steps/sendEmail.js b/packages/server/src/workflows/steps/sendEmail.js index b384b026fb..ea102e8203 100644 --- a/packages/server/src/workflows/steps/sendEmail.js +++ b/packages/server/src/workflows/steps/sendEmail.js @@ -53,7 +53,7 @@ module.exports.run = async function({ inputs }) { to: inputs.to, from: inputs.from, subject: inputs.subject, - text: inputs.text ? inputs.text : "Empty", + text: inputs.contents ? inputs.contents : "Empty", } try {