From c1e1ba51f33959cee9a0f635563e86a0ed3eae59 Mon Sep 17 00:00:00 2001 From: Dean Date: Mon, 28 Nov 2022 17:25:10 +0000 Subject: [PATCH 1/2] Disabled the ability to rename the Sample Data datasource. Updated the backend to ensure that renaming doesn't alter its structure and block deletion --- .../popovers/EditDatasourcePopover.svelte | 5 ++++- packages/builder/src/constants/backend/index.js | 1 + .../datasource_internal_bb_default/_layout.svelte | 3 ++- packages/server/src/api/controllers/datasource.ts | 9 +++++++-- .../server/src/db/defaultData/datasource_bb_default.js | 8 +++++++- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/popovers/EditDatasourcePopover.svelte b/packages/builder/src/components/backend/DatasourceNavigator/popovers/EditDatasourcePopover.svelte index ae0023f682..165ed18ad8 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/popovers/EditDatasourcePopover.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/popovers/EditDatasourcePopover.svelte @@ -5,6 +5,7 @@ import { ActionMenu, MenuItem, Icon } from "@budibase/bbui" import ConfirmDialog from "components/common/ConfirmDialog.svelte" import UpdateDatasourceModal from "components/backend/DatasourceNavigator/modals/UpdateDatasourceModal.svelte" + import { BUDIBASE_DATASOURCE_TYPE } from "constants/backend" export let datasource @@ -42,7 +43,9 @@
- Edit + {#if datasource.type !== BUDIBASE_DATASOURCE_TYPE} + Edit + {/if} Delete diff --git a/packages/builder/src/constants/backend/index.js b/packages/builder/src/constants/backend/index.js index f3898e1d9e..35e250d459 100644 --- a/packages/builder/src/constants/backend/index.js +++ b/packages/builder/src/constants/backend/index.js @@ -174,6 +174,7 @@ export const SWITCHABLE_TYPES = [ ] export const BUDIBASE_INTERNAL_DB_ID = "bb_internal" +export const DEFAULT_BB_DATASOURCE_ID = "datasource_internal_bb_default" export const BUDIBASE_DATASOURCE_TYPE = "budibase" export const DB_TYPE_INTERNAL = "internal" export const DB_TYPE_EXTERNAL = "external" diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/datasource_internal_bb_default/_layout.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/datasource_internal_bb_default/_layout.svelte index 249f23d8b6..168290ef02 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/datasource_internal_bb_default/_layout.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/datasource_internal_bb_default/_layout.svelte @@ -1,7 +1,8 @@ diff --git a/packages/server/src/api/controllers/datasource.ts b/packages/server/src/api/controllers/datasource.ts index 511eb8ab74..cb1eb9ccaf 100644 --- a/packages/server/src/api/controllers/datasource.ts +++ b/packages/server/src/api/controllers/datasource.ts @@ -152,7 +152,12 @@ export async function update(ctx: BBContext) { let datasource = await db.get(datasourceId) const auth = datasource.config.auth await invalidateVariables(datasource, ctx.request.body) - datasource = { ...datasource, ...ctx.request.body } + + const dataSourceBody = !datasource.plus + ? { name: ctx.request.body?.name } + : ctx.request.body + + datasource = { ...datasource, ...dataSourceBody } if (auth && !ctx.request.body.auth) { // don't strip auth config from DB datasource.config.auth = auth @@ -163,7 +168,7 @@ export async function update(ctx: BBContext) { datasource._rev = response.rev // Drain connection pools when configuration is changed - if (datasource.source) { + if (datasource.source && datasource.plus) { const source = await getIntegration(datasource.source) if (source && source.pool) { await source.pool.end() diff --git a/packages/server/src/db/defaultData/datasource_bb_default.js b/packages/server/src/db/defaultData/datasource_bb_default.js index f12ee2c97d..0716b4bddf 100644 --- a/packages/server/src/db/defaultData/datasource_bb_default.js +++ b/packages/server/src/db/defaultData/datasource_bb_default.js @@ -631,8 +631,14 @@ exports.buildDefaultDocs = () => { ) }) + const dataSource = { + ...this.DEFAULT_BB_DATASOURCE, + updatedAt: new Date().toISOString(), + createdAt: new Date().toISOString(), + } + return [ - this.DEFAULT_BB_DATASOURCE, + dataSource, inventoryData.table, employeeData.table, jobData.table, From 2de437aaa710d7a13e8491a28fef83e5d862bd8c Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 29 Nov 2022 16:08:31 +0000 Subject: [PATCH 2/2] Fix to ensure only the budibase datasource type is altered on save --- packages/server/src/api/controllers/datasource.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/server/src/api/controllers/datasource.ts b/packages/server/src/api/controllers/datasource.ts index cb1eb9ccaf..d47629ed3e 100644 --- a/packages/server/src/api/controllers/datasource.ts +++ b/packages/server/src/api/controllers/datasource.ts @@ -153,7 +153,9 @@ export async function update(ctx: BBContext) { const auth = datasource.config.auth await invalidateVariables(datasource, ctx.request.body) - const dataSourceBody = !datasource.plus + const isBudibaseSource = datasource.type === dbCore.BUDIBASE_DATASOURCE_TYPE + + const dataSourceBody = isBudibaseSource ? { name: ctx.request.body?.name } : ctx.request.body @@ -168,7 +170,7 @@ export async function update(ctx: BBContext) { datasource._rev = response.rev // Drain connection pools when configuration is changed - if (datasource.source && datasource.plus) { + if (datasource.source && !isBudibaseSource) { const source = await getIntegration(datasource.source) if (source && source.pool) { await source.pool.end()