Add checks to shared-core

This commit is contained in:
Adria Navarro 2024-07-23 12:07:05 +02:00
parent 35bbccec67
commit b4767cea7c
5 changed files with 19 additions and 21 deletions

View File

@ -1,4 +1,5 @@
import * as triggers from "../../automations/triggers"
import { sdk as coreSdk } from "@budibase/shared-core"
import { DocumentType } from "../../db/utils"
import { updateTestHistory, removeDeprecated } from "../../automations/utils"
import { setTestFlag, clearTestFlag } from "../../utilities/redis"
@ -12,7 +13,6 @@ import {
UserCtx,
DeleteAutomationResponse,
FetchAutomationResponse,
AutomationTriggerStepId,
} from "@budibase/types"
import { getActionDefinitions as actionDefs } from "../../automations/actions"
import sdk from "../../sdk"
@ -96,9 +96,7 @@ export async function destroy(ctx: UserCtx<void, DeleteAutomationResponse>) {
const automationId = ctx.params.id
const automation = await sdk.automations.get(ctx.params.id)
if (
automation.definition.trigger.stepId === AutomationTriggerStepId.ROW_ACTION
) {
if (coreSdk.automations.isRowAction(automation)) {
ctx.throw("Row actions cannot be deleted", 400)
}

View File

@ -1,9 +1,5 @@
import {
Automation,
AutomationTriggerStepId,
Webhook,
WebhookActionType,
} from "@budibase/types"
import { Automation, Webhook, WebhookActionType } from "@budibase/types"
import { sdk } from "@budibase/shared-core"
import { generateAutomationID, getAutomationParams } from "../../../db/utils"
import { deleteEntityMetadata } from "../../../utilities"
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")
}
}
function isRowAction(automation: Automation) {
const result =
automation.definition.trigger.stepId === AutomationTriggerStepId.ROW_ACTION
return result
}

View File

@ -2,9 +2,9 @@ import {
Automation,
AutomationActionStepId,
AutomationBuilderData,
AutomationTriggerStepId,
TableRowActions,
} from "@budibase/types"
import { sdk as coreSdk } from "@budibase/shared-core"
export function checkForCollectStep(automation: Automation) {
return automation.definition.steps.some(
@ -39,14 +39,13 @@ export async function getBuilderData(
const result: Record<string, AutomationBuilderData> = {}
for (const automation of automations) {
const { trigger } = automation.definition
const isRowAction = trigger.stepId === AutomationTriggerStepId.ROW_ACTION
const isRowAction = coreSdk.automations.isRowAction(automation)
if (!isRowAction) {
result[automation._id!] = { displayName: automation.name }
continue
}
const { tableId, rowActionId } = trigger.inputs
const { tableId, rowActionId } = automation.definition.trigger.inputs
const tableName = await getTableName(tableId)

View File

@ -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
}

View File

@ -1,2 +1,3 @@
export * as applications from "./applications"
export * as automations from "./automations"
export * as users from "./users"