Add checks to shared-core
This commit is contained in:
parent
35bbccec67
commit
b4767cea7c
|
@ -1,4 +1,5 @@
|
||||||
import * as triggers from "../../automations/triggers"
|
import * as triggers from "../../automations/triggers"
|
||||||
|
import { sdk as coreSdk } from "@budibase/shared-core"
|
||||||
import { DocumentType } from "../../db/utils"
|
import { DocumentType } from "../../db/utils"
|
||||||
import { updateTestHistory, removeDeprecated } from "../../automations/utils"
|
import { updateTestHistory, removeDeprecated } from "../../automations/utils"
|
||||||
import { setTestFlag, clearTestFlag } from "../../utilities/redis"
|
import { setTestFlag, clearTestFlag } from "../../utilities/redis"
|
||||||
|
@ -12,7 +13,6 @@ import {
|
||||||
UserCtx,
|
UserCtx,
|
||||||
DeleteAutomationResponse,
|
DeleteAutomationResponse,
|
||||||
FetchAutomationResponse,
|
FetchAutomationResponse,
|
||||||
AutomationTriggerStepId,
|
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { getActionDefinitions as actionDefs } from "../../automations/actions"
|
import { getActionDefinitions as actionDefs } from "../../automations/actions"
|
||||||
import sdk from "../../sdk"
|
import sdk from "../../sdk"
|
||||||
|
@ -96,9 +96,7 @@ export async function destroy(ctx: UserCtx<void, DeleteAutomationResponse>) {
|
||||||
const automationId = ctx.params.id
|
const automationId = ctx.params.id
|
||||||
|
|
||||||
const automation = await sdk.automations.get(ctx.params.id)
|
const automation = await sdk.automations.get(ctx.params.id)
|
||||||
if (
|
if (coreSdk.automations.isRowAction(automation)) {
|
||||||
automation.definition.trigger.stepId === AutomationTriggerStepId.ROW_ACTION
|
|
||||||
) {
|
|
||||||
ctx.throw("Row actions cannot be deleted", 400)
|
ctx.throw("Row actions cannot be deleted", 400)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
import {
|
import { Automation, Webhook, WebhookActionType } from "@budibase/types"
|
||||||
Automation,
|
import { sdk } from "@budibase/shared-core"
|
||||||
AutomationTriggerStepId,
|
|
||||||
Webhook,
|
|
||||||
WebhookActionType,
|
|
||||||
} from "@budibase/types"
|
|
||||||
import { generateAutomationID, getAutomationParams } from "../../../db/utils"
|
import { generateAutomationID, getAutomationParams } from "../../../db/utils"
|
||||||
import { deleteEntityMetadata } from "../../../utilities"
|
import { deleteEntityMetadata } from "../../../utilities"
|
||||||
import { MetadataTypes } from "../../../constants"
|
import { MetadataTypes } from "../../../constants"
|
||||||
|
@ -286,13 +282,10 @@ function guardInvalidUpdatesAndThrow(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isRowAction(automation) && automation.name !== oldAutomation.name) {
|
if (
|
||||||
|
sdk.automations.isRowAction(automation) &&
|
||||||
|
automation.name !== oldAutomation.name
|
||||||
|
) {
|
||||||
throw new Error("Row actions cannot be renamed")
|
throw new Error("Row actions cannot be renamed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isRowAction(automation: Automation) {
|
|
||||||
const result =
|
|
||||||
automation.definition.trigger.stepId === AutomationTriggerStepId.ROW_ACTION
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,9 +2,9 @@ import {
|
||||||
Automation,
|
Automation,
|
||||||
AutomationActionStepId,
|
AutomationActionStepId,
|
||||||
AutomationBuilderData,
|
AutomationBuilderData,
|
||||||
AutomationTriggerStepId,
|
|
||||||
TableRowActions,
|
TableRowActions,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
import { sdk as coreSdk } from "@budibase/shared-core"
|
||||||
|
|
||||||
export function checkForCollectStep(automation: Automation) {
|
export function checkForCollectStep(automation: Automation) {
|
||||||
return automation.definition.steps.some(
|
return automation.definition.steps.some(
|
||||||
|
@ -39,14 +39,13 @@ export async function getBuilderData(
|
||||||
|
|
||||||
const result: Record<string, AutomationBuilderData> = {}
|
const result: Record<string, AutomationBuilderData> = {}
|
||||||
for (const automation of automations) {
|
for (const automation of automations) {
|
||||||
const { trigger } = automation.definition
|
const isRowAction = coreSdk.automations.isRowAction(automation)
|
||||||
const isRowAction = trigger.stepId === AutomationTriggerStepId.ROW_ACTION
|
|
||||||
if (!isRowAction) {
|
if (!isRowAction) {
|
||||||
result[automation._id!] = { displayName: automation.name }
|
result[automation._id!] = { displayName: automation.name }
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const { tableId, rowActionId } = trigger.inputs
|
const { tableId, rowActionId } = automation.definition.trigger.inputs
|
||||||
|
|
||||||
const tableName = await getTableName(tableId)
|
const tableName = await getTableName(tableId)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
import { Automation, AutomationTriggerStepId } from "@budibase/types"
|
||||||
|
|
||||||
|
export function isRowAction(automation: Automation) {
|
||||||
|
const result =
|
||||||
|
automation.definition.trigger.stepId === AutomationTriggerStepId.ROW_ACTION
|
||||||
|
return result
|
||||||
|
}
|
|
@ -1,2 +1,3 @@
|
||||||
export * as applications from "./applications"
|
export * as applications from "./applications"
|
||||||
|
export * as automations from "./automations"
|
||||||
export * as users from "./users"
|
export * as users from "./users"
|
||||||
|
|
Loading…
Reference in New Issue