From 713500febbab0c1c15dd35ff22ddc2a6ed21ecb5 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 23 Oct 2024 12:18:53 +0200 Subject: [PATCH 01/14] Add sdk.automation.find --- packages/server/src/sdk/app/automations/crud.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/server/src/sdk/app/automations/crud.ts b/packages/server/src/sdk/app/automations/crud.ts index 3888e6882a..6113499915 100644 --- a/packages/server/src/sdk/app/automations/crud.ts +++ b/packages/server/src/sdk/app/automations/crud.ts @@ -99,6 +99,12 @@ export async function get(automationId: string) { return trimUnexpectedObjectFields(result) } +export async function find(ids: string[]) { + const db = getDb() + const result = await db.getMultiple(ids) + return result.map(trimUnexpectedObjectFields) +} + export async function create(automation: Automation) { automation = trimUnexpectedObjectFields(automation) const db = getDb() From 1f01277ee8f544e03d629ac338b4ed313730abab Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 23 Oct 2024 12:22:07 +0200 Subject: [PATCH 02/14] Clean code --- packages/server/src/sdk/app/rowActions.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/server/src/sdk/app/rowActions.ts b/packages/server/src/sdk/app/rowActions.ts index 08a173ee13..fa72079223 100644 --- a/packages/server/src/sdk/app/rowActions.ts +++ b/packages/server/src/sdk/app/rowActions.ts @@ -248,13 +248,8 @@ export async function run( throw new HTTPError("Table not found", 404) } - const rowActions = await getAll(tableId) - const rowAction = rowActions?.actions[rowActionId] - if (!rowAction) { - throw new HTTPError("Row action not found", 404) - } - - const automation = await sdk.automations.get(rowAction.automationId) + const { automationId } = await get(tableId, rowActionId) + const automation = await sdk.automations.get(automationId) const row = await sdk.rows.find(tableId, rowId) await triggers.externalTrigger( From 076f21108f0e928734ec4d5b5a3babdd2752c270 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 23 Oct 2024 12:30:23 +0200 Subject: [PATCH 03/14] Remove unnecessary row action update endpoint --- .../src/api/controllers/rowAction/crud.ts | 20 ------------------- packages/server/src/api/routes/rowAction.ts | 6 ------ packages/server/src/sdk/app/rowActions.ts | 14 ------------- 3 files changed, 40 deletions(-) diff --git a/packages/server/src/api/controllers/rowAction/crud.ts b/packages/server/src/api/controllers/rowAction/crud.ts index ca84b2ea30..71fbce16e6 100644 --- a/packages/server/src/api/controllers/rowAction/crud.ts +++ b/packages/server/src/api/controllers/rowAction/crud.ts @@ -68,26 +68,6 @@ export async function create( ctx.status = 201 } -export async function update( - ctx: Ctx -) { - const table = await getTable(ctx) - const tableId = table._id! - const { actionId } = ctx.params - - const action = await sdk.rowActions.update(tableId, actionId, { - name: ctx.request.body.name, - }) - - ctx.body = { - tableId, - id: action.id, - name: action.name, - automationId: action.automationId, - allowedSources: flattenAllowedSources(tableId, action.permissions), - } -} - export async function remove(ctx: Ctx) { const table = await getTable(ctx) const { actionId } = ctx.params diff --git a/packages/server/src/api/routes/rowAction.ts b/packages/server/src/api/routes/rowAction.ts index 3d14633509..b4b595164c 100644 --- a/packages/server/src/api/routes/rowAction.ts +++ b/packages/server/src/api/routes/rowAction.ts @@ -40,12 +40,6 @@ router rowActionValidator(), rowActionController.create ) - .put( - "/api/tables/:tableId/actions/:actionId", - authorized(BUILDER), - rowActionValidator(), - rowActionController.update - ) .delete( "/api/tables/:tableId/actions/:actionId", authorized(BUILDER), diff --git a/packages/server/src/sdk/app/rowActions.ts b/packages/server/src/sdk/app/rowActions.ts index fa72079223..f1064396fc 100644 --- a/packages/server/src/sdk/app/rowActions.ts +++ b/packages/server/src/sdk/app/rowActions.ts @@ -159,20 +159,6 @@ async function updateDoc( } } -export async function update( - tableId: string, - rowActionId: string, - rowActionData: { name: string } -) { - const newName = rowActionData.name.trim() - - return await updateDoc(tableId, rowActionId, actionsDoc => { - ensureUniqueAndThrow(actionsDoc, newName, rowActionId) - actionsDoc.actions[rowActionId].name = newName - return actionsDoc - }) -} - async function guardView(tableId: string, viewId: string) { let view if (docIds.isViewId(viewId)) { From 7781e75491b5430850452db05a9b691c4d2bd875 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 23 Oct 2024 12:47:06 +0200 Subject: [PATCH 04/14] Simplify row action permissions response --- .../src/api/controllers/rowAction/crud.ts | 34 +++++++------------ packages/types/src/api/web/app/rowAction.ts | 12 +++++-- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/packages/server/src/api/controllers/rowAction/crud.ts b/packages/server/src/api/controllers/rowAction/crud.ts index 71fbce16e6..d6eadb65b1 100644 --- a/packages/server/src/api/controllers/rowAction/crud.ts +++ b/packages/server/src/api/controllers/rowAction/crud.ts @@ -2,9 +2,9 @@ import { CreateRowActionRequest, Ctx, RowActionPermissions, + RowActionPermissionsResponse, RowActionResponse, RowActionsResponse, - UpdateRowActionRequest, } from "@budibase/types" import sdk from "../../../sdk" @@ -76,22 +76,22 @@ export async function remove(ctx: Ctx) { ctx.status = 204 } -export async function setTablePermission(ctx: Ctx) { +export async function setTablePermission( + ctx: Ctx +) { const table = await getTable(ctx) const tableId = table._id! const { actionId } = ctx.params const action = await sdk.rowActions.setTablePermission(tableId, actionId) ctx.body = { - tableId, - id: action.id, - name: action.name, - automationId: action.automationId, allowedSources: flattenAllowedSources(tableId, action.permissions), } } -export async function unsetTablePermission(ctx: Ctx) { +export async function unsetTablePermission( + ctx: Ctx +) { const table = await getTable(ctx) const tableId = table._id! const { actionId } = ctx.params @@ -99,15 +99,13 @@ export async function unsetTablePermission(ctx: Ctx) { const action = await sdk.rowActions.unsetTablePermission(tableId, actionId) ctx.body = { - tableId, - id: action.id, - name: action.name, - automationId: action.automationId, allowedSources: flattenAllowedSources(tableId, action.permissions), } } -export async function setViewPermission(ctx: Ctx) { +export async function setViewPermission( + ctx: Ctx +) { const table = await getTable(ctx) const tableId = table._id! const { actionId, viewId } = ctx.params @@ -118,15 +116,13 @@ export async function setViewPermission(ctx: Ctx) { viewId ) ctx.body = { - tableId, - id: action.id, - name: action.name, - automationId: action.automationId, allowedSources: flattenAllowedSources(tableId, action.permissions), } } -export async function unsetViewPermission(ctx: Ctx) { +export async function unsetViewPermission( + ctx: Ctx +) { const table = await getTable(ctx) const tableId = table._id! const { actionId, viewId } = ctx.params @@ -138,10 +134,6 @@ export async function unsetViewPermission(ctx: Ctx) { ) ctx.body = { - tableId, - id: action.id, - name: action.name, - automationId: action.automationId, allowedSources: flattenAllowedSources(tableId, action.permissions), } } diff --git a/packages/types/src/api/web/app/rowAction.ts b/packages/types/src/api/web/app/rowAction.ts index 0061be275e..84e4e529ed 100644 --- a/packages/types/src/api/web/app/rowAction.ts +++ b/packages/types/src/api/web/app/rowAction.ts @@ -1,14 +1,17 @@ interface RowActionData { name: string } +interface RowActionPermissionsData { + allowedSources: string[] | undefined +} export interface CreateRowActionRequest extends RowActionData {} -export interface UpdateRowActionRequest extends RowActionData {} -export interface RowActionResponse extends RowActionData { +export interface RowActionResponse + extends RowActionData, + RowActionPermissionsData { id: string tableId: string automationId: string - allowedSources: string[] | undefined } export interface RowActionsResponse { @@ -18,3 +21,6 @@ export interface RowActionsResponse { export interface RowActionTriggerRequest { rowId: string } + +export interface RowActionPermissionsResponse + extends RowActionPermissionsData {} From 015854f1a2fd207f40b4552b4038aa4238d107c3 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 23 Oct 2024 12:49:42 +0200 Subject: [PATCH 05/14] Dont persist row action name --- .../src/api/controllers/rowAction/crud.ts | 12 +++++- .../server/src/sdk/app/automations/utils.ts | 17 +------- packages/server/src/sdk/app/rowActions.ts | 39 ++++++++++++------- packages/types/src/documents/app/rowAction.ts | 1 - 4 files changed, 36 insertions(+), 33 deletions(-) diff --git a/packages/server/src/api/controllers/rowAction/crud.ts b/packages/server/src/api/controllers/rowAction/crud.ts index d6eadb65b1..014ebcf426 100644 --- a/packages/server/src/api/controllers/rowAction/crud.ts +++ b/packages/server/src/api/controllers/rowAction/crud.ts @@ -30,6 +30,16 @@ export async function find(ctx: Ctx) { } const { actions } = rowActions + const automations = await sdk.automations.find( + Object.values(actions).map(({ automationId }) => automationId) + ) + const automationNames = automations.reduce>( + (names, a) => { + names[a._id] = a.name + return names + }, + {} + ) const result: RowActionsResponse = { actions: Object.entries(actions).reduce>( (acc, [key, action]) => ({ @@ -37,7 +47,7 @@ export async function find(ctx: Ctx) { [key]: { id: key, tableId, - name: action.name, + name: automationNames[action.automationId], automationId: action.automationId, allowedSources: flattenAllowedSources(tableId, action.permissions), }, diff --git a/packages/server/src/sdk/app/automations/utils.ts b/packages/server/src/sdk/app/automations/utils.ts index 8b397df75f..f5ae8bf948 100644 --- a/packages/server/src/sdk/app/automations/utils.ts +++ b/packages/server/src/sdk/app/automations/utils.ts @@ -2,7 +2,6 @@ import { Automation, AutomationActionStepId, AutomationBuilderData, - TableRowActions, } from "@budibase/types" import { sdk as coreSdk } from "@budibase/shared-core" import sdk from "../../../sdk" @@ -26,15 +25,6 @@ export async function getBuilderData( return tableNameCache[tableId] } - const rowActionNameCache: Record = {} - async function getRowActionName(tableId: string, rowActionId: string) { - if (!rowActionNameCache[tableId]) { - rowActionNameCache[tableId] = await sdk.rowActions.getAll(tableId) - } - - return rowActionNameCache[tableId]?.actions[rowActionId]?.name - } - const result: Record = {} for (const automation of automations) { const isRowAction = coreSdk.automations.isRowAction(automation) @@ -49,12 +39,7 @@ export async function getBuilderData( } const tableName = await getTableName(tableId) - const rowActionName = await getRowActionName(tableId, rowActionId) - - if (!rowActionName) { - throw new Error(`Row action not found: ${rowActionId}`) - } - + const rowActionName = automation.name result[automation._id!] = { displayName: rowActionName, triggerInfo: { diff --git a/packages/server/src/sdk/app/rowActions.ts b/packages/server/src/sdk/app/rowActions.ts index f1064396fc..c6182ed38b 100644 --- a/packages/server/src/sdk/app/rowActions.ts +++ b/packages/server/src/sdk/app/rowActions.ts @@ -13,16 +13,17 @@ import { definitions as TRIGGER_DEFINITIONS } from "../../automations/triggerInf import * as triggers from "../../automations/triggers" import sdk from ".." -function ensureUniqueAndThrow( +async function ensureUniqueAndThrow( doc: TableRowActions, name: string, existingRowActionId?: string ) { + const names = await getNames(doc) + name = name.toLowerCase() + if ( - Object.entries(doc.actions).find( - ([id, a]) => - a.name.toLowerCase() === name.toLowerCase() && - id !== existingRowActionId + Object.entries(names).find( + ([id, name]) => name === name && id !== existingRowActionId ) ) { throw new HTTPError("A row action with the same name already exists.", 409) @@ -34,18 +35,12 @@ export async function create(tableId: string, rowAction: { name: string }) { const db = context.getAppDB() const rowActionsId = generateRowActionsID(tableId) - let doc: TableRowActions - try { - doc = await db.get(rowActionsId) - } catch (e: any) { - if (e.status !== 404) { - throw e - } - + let doc = await db.tryGet(rowActionsId) + if (!doc) { doc = { _id: rowActionsId, actions: {} } } - ensureUniqueAndThrow(doc, action.name) + await ensureUniqueAndThrow(doc, action.name) const appId = context.getAppId() if (!appId) { @@ -74,7 +69,6 @@ export async function create(tableId: string, rowAction: { name: string }) { }) doc.actions[newRowActionId] = { - name: action.name, automationId: automation._id!, permissions: { table: { runAllowed: true }, @@ -85,6 +79,7 @@ export async function create(tableId: string, rowAction: { name: string }) { return { id: newRowActionId, + name: automation.name, ...doc.actions[newRowActionId], } } @@ -253,3 +248,17 @@ export async function run( { getResponses: true } ) } + +export async function getNames(actions: TableRowActions) { + const automations = await sdk.automations.find( + Object.values(actions).map(({ automationId }) => automationId) + ) + const automationNames = automations.reduce>( + (names, a) => { + names[a._id] = a.name + return names + }, + {} + ) + return automationNames +} diff --git a/packages/types/src/documents/app/rowAction.ts b/packages/types/src/documents/app/rowAction.ts index 071b480b1c..db3637b708 100644 --- a/packages/types/src/documents/app/rowAction.ts +++ b/packages/types/src/documents/app/rowAction.ts @@ -6,7 +6,6 @@ export interface TableRowActions extends Document { } export interface RowActionData { - name: string automationId: string permissions: RowActionPermissions } From dab38265dbc942364ec601be85e33e5cc298b4f2 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 23 Oct 2024 12:54:32 +0200 Subject: [PATCH 06/14] Allow renaming row actions --- packages/server/src/sdk/app/automations/crud.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/server/src/sdk/app/automations/crud.ts b/packages/server/src/sdk/app/automations/crud.ts index 6113499915..b982d5b45e 100644 --- a/packages/server/src/sdk/app/automations/crud.ts +++ b/packages/server/src/sdk/app/automations/crud.ts @@ -1,4 +1,3 @@ -import { sdk } from "@budibase/shared-core" import { Automation, RequiredKeys, @@ -295,13 +294,6 @@ function guardInvalidUpdatesAndThrow( } }) } - - if ( - sdk.automations.isRowAction(automation) && - automation.name !== oldAutomation.name - ) { - throw new Error("Row actions cannot be renamed") - } } function trimUnexpectedObjectFields(automation: T): T { From 2868c840e628e519978e8ff6c274fc5e66c4f5bd Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 23 Oct 2024 13:02:25 +0200 Subject: [PATCH 07/14] Remove duplicated modals --- .../AutomationPanel/AutomationNavItem.svelte | 9 +- .../UpdateRowActionModal.svelte | 83 ------------------- 2 files changed, 2 insertions(+), 90 deletions(-) delete mode 100644 packages/builder/src/components/automation/AutomationPanel/UpdateRowActionModal.svelte diff --git a/packages/builder/src/components/automation/AutomationPanel/AutomationNavItem.svelte b/packages/builder/src/components/automation/AutomationPanel/AutomationNavItem.svelte index ec9b956190..14857da373 100644 --- a/packages/builder/src/components/automation/AutomationPanel/AutomationNavItem.svelte +++ b/packages/builder/src/components/automation/AutomationPanel/AutomationNavItem.svelte @@ -17,7 +17,6 @@ let confirmDeleteDialog let updateAutomationDialog - let updateRowActionDialog $: isRowAction = sdk.automations.isRowAction(automation) @@ -92,7 +91,7 @@ name: "Edit", keyBind: null, visible: true, - callback: updateRowActionDialog.show, + callback: updateAutomationDialog.show, }, del, ] @@ -135,8 +134,4 @@ This action cannot be undone. -{#if isRowAction} - -{:else} - -{/if} + diff --git a/packages/builder/src/components/automation/AutomationPanel/UpdateRowActionModal.svelte b/packages/builder/src/components/automation/AutomationPanel/UpdateRowActionModal.svelte deleted file mode 100644 index 20f06608dc..0000000000 --- a/packages/builder/src/components/automation/AutomationPanel/UpdateRowActionModal.svelte +++ /dev/null @@ -1,83 +0,0 @@ - - - - - - - - Learn about automations - - - - - From 022ec12b1bdb16ec32c7ac22c80b63fecf03bfab Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 23 Oct 2024 13:08:15 +0200 Subject: [PATCH 08/14] Clean --- .../automation/AutomationPanel/AutomationNavItem.svelte | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/builder/src/components/automation/AutomationPanel/AutomationNavItem.svelte b/packages/builder/src/components/automation/AutomationPanel/AutomationNavItem.svelte index 14857da373..50814897b4 100644 --- a/packages/builder/src/components/automation/AutomationPanel/AutomationNavItem.svelte +++ b/packages/builder/src/components/automation/AutomationPanel/AutomationNavItem.svelte @@ -9,7 +9,6 @@ import { sdk } from "@budibase/shared-core" import ConfirmDialog from "components/common/ConfirmDialog.svelte" import UpdateAutomationModal from "components/automation/AutomationPanel/UpdateAutomationModal.svelte" - import UpdateRowActionModal from "components/automation/AutomationPanel/UpdateRowActionModal.svelte" import NavItem from "components/common/NavItem.svelte" export let automation From 8f990725523d1ec71a0b62313f91d7789d22d6e4 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 23 Oct 2024 13:08:22 +0200 Subject: [PATCH 09/14] Reuse --- packages/server/src/api/controllers/rowAction/crud.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/packages/server/src/api/controllers/rowAction/crud.ts b/packages/server/src/api/controllers/rowAction/crud.ts index 014ebcf426..3baaff6fcc 100644 --- a/packages/server/src/api/controllers/rowAction/crud.ts +++ b/packages/server/src/api/controllers/rowAction/crud.ts @@ -30,16 +30,7 @@ export async function find(ctx: Ctx) { } const { actions } = rowActions - const automations = await sdk.automations.find( - Object.values(actions).map(({ automationId }) => automationId) - ) - const automationNames = automations.reduce>( - (names, a) => { - names[a._id] = a.name - return names - }, - {} - ) + const automationNames = await sdk.rowActions.getNames(rowActions) const result: RowActionsResponse = { actions: Object.entries(actions).reduce>( (acc, [key, action]) => ({ From b4a979ed97cffc41a32cc23967137eb4917a8036 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 23 Oct 2024 13:10:50 +0200 Subject: [PATCH 10/14] Fix get names --- packages/server/src/sdk/app/rowActions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/sdk/app/rowActions.ts b/packages/server/src/sdk/app/rowActions.ts index c6182ed38b..d5c7666edb 100644 --- a/packages/server/src/sdk/app/rowActions.ts +++ b/packages/server/src/sdk/app/rowActions.ts @@ -249,7 +249,7 @@ export async function run( ) } -export async function getNames(actions: TableRowActions) { +export async function getNames({ actions }: TableRowActions) { const automations = await sdk.automations.find( Object.values(actions).map(({ automationId }) => automationId) ) From 1fef7838f2ba17efc7a320efd12cc61f9616c819 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 23 Oct 2024 13:15:07 +0200 Subject: [PATCH 11/14] Check names properly --- packages/server/src/sdk/app/rowActions.ts | 3 ++- packages/server/src/tests/utilities/api/rowAction.ts | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/server/src/sdk/app/rowActions.ts b/packages/server/src/sdk/app/rowActions.ts index d5c7666edb..6a0a803bd5 100644 --- a/packages/server/src/sdk/app/rowActions.ts +++ b/packages/server/src/sdk/app/rowActions.ts @@ -23,7 +23,8 @@ async function ensureUniqueAndThrow( if ( Object.entries(names).find( - ([id, name]) => name === name && id !== existingRowActionId + ([automationId, automationName]) => + automationName === name && automationId !== existingRowActionId ) ) { throw new HTTPError("A row action with the same name already exists.", 409) diff --git a/packages/server/src/tests/utilities/api/rowAction.ts b/packages/server/src/tests/utilities/api/rowAction.ts index 0fd5936257..e18f2ce6b6 100644 --- a/packages/server/src/tests/utilities/api/rowAction.ts +++ b/packages/server/src/tests/utilities/api/rowAction.ts @@ -1,5 +1,6 @@ import { CreateRowActionRequest, + RowActionPermissionsResponse, RowActionResponse, RowActionsResponse, RowActionTriggerRequest, @@ -78,7 +79,7 @@ export class RowActionAPI extends TestAPI { expectations?: Expectations, config?: { publicUser?: boolean } ) => { - return await this._post( + return await this._post( `/api/tables/${tableId}/actions/${rowActionId}/permissions`, { expectations: { @@ -96,7 +97,7 @@ export class RowActionAPI extends TestAPI { expectations?: Expectations, config?: { publicUser?: boolean } ) => { - return await this._delete( + return await this._delete( `/api/tables/${tableId}/actions/${rowActionId}/permissions`, { expectations: { @@ -115,7 +116,7 @@ export class RowActionAPI extends TestAPI { expectations?: Expectations, config?: { publicUser?: boolean } ) => { - return await this._post( + return await this._post( `/api/tables/${tableId}/actions/${rowActionId}/permissions/${viewId}`, { expectations: { @@ -134,7 +135,7 @@ export class RowActionAPI extends TestAPI { expectations?: Expectations, config?: { publicUser?: boolean } ) => { - return await this._delete( + return await this._delete( `/api/tables/${tableId}/actions/${rowActionId}/permissions/${viewId}`, { expectations: { From 732d701a868bd7b198cb5a9dcd64b12fdf565cb5 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 23 Oct 2024 13:16:55 +0200 Subject: [PATCH 12/14] Remove row action update tests --- .../src/api/routes/tests/rowAction.spec.ts | 123 ------------------ .../src/tests/utilities/api/rowAction.ts | 17 --- 2 files changed, 140 deletions(-) diff --git a/packages/server/src/api/routes/tests/rowAction.spec.ts b/packages/server/src/api/routes/tests/rowAction.spec.ts index c0b5c4210f..5cec83fe23 100644 --- a/packages/server/src/api/routes/tests/rowAction.spec.ts +++ b/packages/server/src/api/routes/tests/rowAction.spec.ts @@ -328,129 +328,6 @@ describe("/rowsActions", () => { }) }) - describe("update", () => { - unauthorisedTests((expectations, testConfig) => - config.api.rowAction.update( - tableId, - generator.guid(), - createRowActionRequest(), - expectations, - testConfig - ) - ) - - it("can update existing actions", async () => { - for (const rowAction of createRowActionRequests(3)) { - await createRowAction(tableId, rowAction) - } - - const persisted = await config.api.rowAction.find(tableId) - - const [actionId, actionData] = _.sample( - Object.entries(persisted.actions) - )! - - const updatedName = generator.string() - - const res = await config.api.rowAction.update(tableId, actionId, { - name: updatedName, - }) - - expect(res).toEqual({ - id: actionId, - tableId, - name: updatedName, - automationId: actionData.automationId, - allowedSources: [tableId], - }) - - expect(await config.api.rowAction.find(tableId)).toEqual( - expect.objectContaining({ - actions: expect.objectContaining({ - [actionId]: { - name: updatedName, - id: actionData.id, - tableId: actionData.tableId, - automationId: actionData.automationId, - allowedSources: [tableId], - }, - }), - }) - ) - }) - - it("trims row action names", async () => { - const rowAction = await createRowAction(tableId, createRowActionRequest()) - - const res = await config.api.rowAction.update(tableId, rowAction.id, { - name: " action name ", - }) - - expect(res).toEqual(expect.objectContaining({ name: "action name" })) - - expect(await config.api.rowAction.find(tableId)).toEqual( - expect.objectContaining({ - actions: expect.objectContaining({ - [rowAction.id]: expect.objectContaining({ - name: "action name", - }), - }), - }) - ) - }) - - it("throws Bad Request when trying to update by a non-existing id", async () => { - await createRowAction(tableId, createRowActionRequest()) - - await config.api.rowAction.update( - tableId, - generator.guid(), - createRowActionRequest(), - { status: 400 } - ) - }) - - it("throws Bad Request when trying to update by a via another table id", async () => { - const otherTable = await config.api.table.save( - setup.structures.basicTable() - ) - await createRowAction(otherTable._id!, createRowActionRequest()) - - const action = await createRowAction(tableId, createRowActionRequest()) - await config.api.rowAction.update( - otherTable._id!, - action.id, - createRowActionRequest(), - { status: 400 } - ) - }) - - it("can not use existing row action names (for the same table)", async () => { - const action1 = await createRowAction(tableId, createRowActionRequest()) - const action2 = await createRowAction(tableId, createRowActionRequest()) - - await config.api.rowAction.update( - tableId, - action1.id, - { name: action2.name }, - { - status: 409, - body: { - message: "A row action with the same name already exists.", - }, - } - ) - }) - - it("does not throw with name conflicts for the same row action", async () => { - const action1 = await createRowAction(tableId, createRowActionRequest()) - - await config.api.rowAction.update(tableId, action1.id, { - name: action1.name, - }) - }) - }) - describe("delete", () => { unauthorisedTests((expectations, testConfig) => config.api.rowAction.delete( diff --git a/packages/server/src/tests/utilities/api/rowAction.ts b/packages/server/src/tests/utilities/api/rowAction.ts index e18f2ce6b6..5d5ef69b8a 100644 --- a/packages/server/src/tests/utilities/api/rowAction.ts +++ b/packages/server/src/tests/utilities/api/rowAction.ts @@ -41,23 +41,6 @@ export class RowActionAPI extends TestAPI { ) } - update = async ( - tableId: string, - rowActionId: string, - rowAction: CreateRowActionRequest, - expectations?: Expectations, - config?: { publicUser?: boolean } - ) => { - return await this._put( - `/api/tables/${tableId}/actions/${rowActionId}`, - { - body: rowAction, - expectations, - ...config, - } - ) - } - delete = async ( tableId: string, rowActionId: string, From 46a7f15fed6d7965e71deab92d2d95db4556f709 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 23 Oct 2024 13:19:24 +0200 Subject: [PATCH 13/14] Fix name checks --- packages/server/src/sdk/app/rowActions.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/server/src/sdk/app/rowActions.ts b/packages/server/src/sdk/app/rowActions.ts index 6a0a803bd5..de73969696 100644 --- a/packages/server/src/sdk/app/rowActions.ts +++ b/packages/server/src/sdk/app/rowActions.ts @@ -19,12 +19,13 @@ async function ensureUniqueAndThrow( existingRowActionId?: string ) { const names = await getNames(doc) - name = name.toLowerCase() + name = name.toLowerCase().trim() if ( Object.entries(names).find( ([automationId, automationName]) => - automationName === name && automationId !== existingRowActionId + automationName.toLowerCase().trim() === name && + automationId !== existingRowActionId ) ) { throw new HTTPError("A row action with the same name already exists.", 409) From 63daa6bcde63209bf922039cc323d38037022b1f Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 23 Oct 2024 14:08:07 +0200 Subject: [PATCH 14/14] Remove obsolete test --- .../sdk/app/automations/tests/index.spec.ts | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/packages/server/src/sdk/app/automations/tests/index.spec.ts b/packages/server/src/sdk/app/automations/tests/index.spec.ts index bf4c886cf0..6c70392300 100644 --- a/packages/server/src/sdk/app/automations/tests/index.spec.ts +++ b/packages/server/src/sdk/app/automations/tests/index.spec.ts @@ -1,5 +1,5 @@ import { sample } from "lodash/fp" -import { Automation, AutomationTriggerStepId } from "@budibase/types" +import { Automation } from "@budibase/types" import { generator } from "@budibase/backend-core/tests" import TestConfiguration from "../../../../tests/utilities/TestConfiguration" import automationSdk from "../" @@ -26,25 +26,6 @@ describe("automation sdk", () => { }) }) - it("cannot rename row action automations", async () => { - await config.doInContext(config.getAppId(), async () => { - const automation = structures.newAutomation({ - trigger: { - ...structures.automationTrigger(), - stepId: AutomationTriggerStepId.ROW_ACTION, - }, - }) - - const response = await automationSdk.create(automation) - - const newName = generator.guid() - const update = { ...response, name: newName } - await expect(automationSdk.update(update)).rejects.toThrow( - "Row actions cannot be renamed" - ) - }) - }) - it.each([ ["trigger", (a: Automation) => a.definition.trigger], ["step", (a: Automation) => a.definition.steps[0]],