Merge branch 'contextual-workflows' of github.com:Budibase/budibase into contextual-workflows

This commit is contained in:
Andrew Kingston 2020-09-18 13:56:10 +01:00
commit eb22b02c84
3 changed files with 20 additions and 6 deletions

View File

@ -8,4 +8,5 @@ module.exports = {
SALT_ROUNDS: process.env.SALT_ROUNDS,
LOGGER: process.env.LOGGER,
BUDIBASE_ENVIRONMENT: process.env.BUDIBASE_ENVIRONMENT,
SENDGRID_API_KEY: process.env.SENDGRID_API_KEY,
}

View File

@ -1,5 +1,6 @@
const environment = require("../../environment")
const sgMail = require("@sendgrid/mail")
sgMail.setApiKey(process.env.SENDGRID_API_KEY)
sgMail.setApiKey(environment.SENDGRID_API_KEY)
module.exports.definition = {
description: "Send an email",
@ -52,7 +53,7 @@ module.exports.run = async function({ inputs }) {
to: inputs.to,
from: inputs.from,
subject: inputs.subject,
text: inputs.text,
text: inputs.text ? inputs.text : "Empty",
}
try {

View File

@ -76,7 +76,7 @@ const BUILTIN_DEFINITIONS = {
},
}
async function queueRelevantWorkflows(event, eventType) {
async function queueRelevantRecordWorkflows(event, eventType) {
if (event.instanceId == null) {
throw `No instanceId specified for ${eventType} - check event emitters.`
}
@ -88,7 +88,13 @@ async function queueRelevantWorkflows(event, eventType) {
const workflows = workflowsToTrigger.rows.map(wf => wf.doc)
for (let workflow of workflows) {
if (!workflow.live) {
let workflowDef = workflow.definition
let workflowTrigger = workflowDef ? workflowDef.trigger : {}
if (
!workflow.live ||
!workflowTrigger.inputs ||
workflowTrigger.inputs.modelId !== event.record.modelId
) {
continue
}
workflowQueue.add({ workflow, event })
@ -96,11 +102,17 @@ async function queueRelevantWorkflows(event, eventType) {
}
emitter.on("record:save", async function(event) {
await queueRelevantWorkflows(event, "record:save")
if (!event || !event.record || !event.record.modelId) {
return
}
await queueRelevantRecordWorkflows(event, "record:save")
})
emitter.on("record:delete", async function(event) {
await queueRelevantWorkflows(event, "record:delete")
if (!event || !event.record || !event.record.modelId) {
return
}
await queueRelevantRecordWorkflows(event, "record:delete")
})
async function fillRecordOutput(workflow, params) {