Changing how automations handle multi-tenancy.
This commit is contained in:
parent
d6ae82e719
commit
d6c47c5027
|
@ -151,7 +151,6 @@ exports.create = async function (ctx) {
|
||||||
const db = new CouchDB(ctx.appId)
|
const db = new CouchDB(ctx.appId)
|
||||||
let automation = ctx.request.body
|
let automation = ctx.request.body
|
||||||
automation.appId = ctx.appId
|
automation.appId = ctx.appId
|
||||||
automation.tenantId = ctx.user.tenantId
|
|
||||||
|
|
||||||
// call through to update if already exists
|
// call through to update if already exists
|
||||||
if (automation._id && automation._rev) {
|
if (automation._id && automation._rev) {
|
||||||
|
|
|
@ -3,6 +3,9 @@ const logic = require("./logic")
|
||||||
const automationUtils = require("./automationUtils")
|
const automationUtils = require("./automationUtils")
|
||||||
const AutomationEmitter = require("../events/AutomationEmitter")
|
const AutomationEmitter = require("../events/AutomationEmitter")
|
||||||
const { processObject } = require("@budibase/string-templates")
|
const { processObject } = require("@budibase/string-templates")
|
||||||
|
const { DEFAULT_TENANT_ID } = require("@budibase/auth").constants
|
||||||
|
const CouchDB = require("../db")
|
||||||
|
const { DocumentTypes } = require("../db/utils")
|
||||||
|
|
||||||
const FILTER_STEP_ID = logic.BUILTIN_DEFINITIONS.FILTER.stepId
|
const FILTER_STEP_ID = logic.BUILTIN_DEFINITIONS.FILTER.stepId
|
||||||
|
|
||||||
|
@ -16,13 +19,13 @@ class Orchestrator {
|
||||||
this._metadata = triggerOutput.metadata
|
this._metadata = triggerOutput.metadata
|
||||||
this._chainCount = this._metadata ? this._metadata.automationChainCount : 0
|
this._chainCount = this._metadata ? this._metadata.automationChainCount : 0
|
||||||
this._appId = triggerOutput.appId
|
this._appId = triggerOutput.appId
|
||||||
|
this._app = null
|
||||||
// remove from context
|
// remove from context
|
||||||
delete triggerOutput.appId
|
delete triggerOutput.appId
|
||||||
delete triggerOutput.metadata
|
delete triggerOutput.metadata
|
||||||
// step zero is never used as the template string is zero indexed for customer facing
|
// step zero is never used as the template string is zero indexed for customer facing
|
||||||
this._context = { steps: [{}], trigger: triggerOutput }
|
this._context = { steps: [{}], trigger: triggerOutput }
|
||||||
this._automation = automation
|
this._automation = automation
|
||||||
this._tenantId = automation.tenantId
|
|
||||||
// create an emitter which has the chain count for this automation run in it, so it can block
|
// create an emitter which has the chain count for this automation run in it, so it can block
|
||||||
// excessive chaining if required
|
// excessive chaining if required
|
||||||
this._emitter = new AutomationEmitter(this._chainCount + 1)
|
this._emitter = new AutomationEmitter(this._chainCount + 1)
|
||||||
|
@ -41,8 +44,19 @@ class Orchestrator {
|
||||||
return step
|
return step
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getApp() {
|
||||||
|
const appId = this._appId
|
||||||
|
if (this._app) {
|
||||||
|
return this._app
|
||||||
|
}
|
||||||
|
const db = new CouchDB(appId)
|
||||||
|
this._app = await db.get(DocumentTypes.APP_METADATA)
|
||||||
|
return this._app
|
||||||
|
}
|
||||||
|
|
||||||
async execute() {
|
async execute() {
|
||||||
let automation = this._automation
|
let automation = this._automation
|
||||||
|
const app = this.getApp()
|
||||||
for (let step of automation.definition.steps) {
|
for (let step of automation.definition.steps) {
|
||||||
let stepFn = await this.getStepFunctionality(step.type, step.stepId)
|
let stepFn = await this.getStepFunctionality(step.type, step.stepId)
|
||||||
step.inputs = await processObject(step.inputs, this._context)
|
step.inputs = await processObject(step.inputs, this._context)
|
||||||
|
@ -58,7 +72,7 @@ class Orchestrator {
|
||||||
apiKey: automation.apiKey,
|
apiKey: automation.apiKey,
|
||||||
emitter: this._emitter,
|
emitter: this._emitter,
|
||||||
context: this._context,
|
context: this._context,
|
||||||
tenantId: this._tenantId,
|
tenantId: app.tenantId || DEFAULT_TENANT_ID,
|
||||||
})
|
})
|
||||||
if (step.stepId === FILTER_STEP_ID && !outputs.success) {
|
if (step.stepId === FILTER_STEP_ID && !outputs.success) {
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue