From b84b272293b6dc68d178f19b8e1dd8488efdcdfb Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 4 Nov 2024 16:48:57 +0100 Subject: [PATCH 01/22] Remove TABLES_DEFAULT_ADMIN flag --- .../backend-core/src/features/features.ts | 1 - packages/server/src/sdk/app/tables/create.ts | 16 +++++---------- packages/server/src/sdk/app/views/index.ts | 20 +++++++------------ packages/types/src/sdk/featureFlag.ts | 1 - 4 files changed, 12 insertions(+), 26 deletions(-) diff --git a/packages/backend-core/src/features/features.ts b/packages/backend-core/src/features/features.ts index e2f8d9b6a1..b9302f9bce 100644 --- a/packages/backend-core/src/features/features.ts +++ b/packages/backend-core/src/features/features.ts @@ -272,7 +272,6 @@ export const flags = new FlagSet({ [FeatureFlag.SQS]: Flag.boolean(true), [FeatureFlag.AI_CUSTOM_CONFIGS]: Flag.boolean(env.isDev()), [FeatureFlag.ENRICHED_RELATIONSHIPS]: Flag.boolean(env.isDev()), - [FeatureFlag.TABLES_DEFAULT_ADMIN]: Flag.boolean(env.isDev()), [FeatureFlag.BUDIBASE_AI]: Flag.boolean(env.isDev()), }) diff --git a/packages/server/src/sdk/app/tables/create.ts b/packages/server/src/sdk/app/tables/create.ts index fa858522bf..1cba26fc46 100644 --- a/packages/server/src/sdk/app/tables/create.ts +++ b/packages/server/src/sdk/app/tables/create.ts @@ -4,7 +4,7 @@ import * as external from "./external" import * as internal from "./internal" import { isExternal } from "./utils" import { setPermissions } from "../permissions" -import { features, roles } from "@budibase/backend-core" +import { roles } from "@budibase/backend-core" export async function create( table: Omit, @@ -18,16 +18,10 @@ export async function create( createdTable = await internal.create(table, rows, userId) } - const setExplicitPermission = await features.flags.isEnabled( - FeatureFlag.TABLES_DEFAULT_ADMIN - ) - - if (setExplicitPermission) { - await setPermissions(createdTable._id!, { - writeRole: roles.BUILTIN_ROLE_IDS.ADMIN, - readRole: roles.BUILTIN_ROLE_IDS.ADMIN, - }) - } + await setPermissions(createdTable._id!, { + writeRole: roles.BUILTIN_ROLE_IDS.ADMIN, + readRole: roles.BUILTIN_ROLE_IDS.ADMIN, + }) return createdTable } diff --git a/packages/server/src/sdk/app/views/index.ts b/packages/server/src/sdk/app/views/index.ts index a259dd5505..9c111ff079 100644 --- a/packages/server/src/sdk/app/views/index.ts +++ b/packages/server/src/sdk/app/views/index.ts @@ -2,7 +2,6 @@ import { BBReferenceFieldSubType, CalculationType, canGroupBy, - FeatureFlag, FieldType, isNumeric, PermissionLevel, @@ -16,7 +15,7 @@ import { ViewV2ColumnEnriched, ViewV2Enriched, } from "@budibase/types" -import { context, docIds, features, HTTPError } from "@budibase/backend-core" +import { context, docIds, HTTPError } from "@budibase/backend-core" import { helpers, PROTECTED_EXTERNAL_COLUMNS, @@ -287,17 +286,12 @@ export async function create( await guardViewSchema(tableId, viewRequest) const view = await pickApi(tableId).create(tableId, viewRequest) - const setExplicitPermission = await features.flags.isEnabled( - FeatureFlag.TABLES_DEFAULT_ADMIN - ) - if (setExplicitPermission) { - // Set permissions to be the same as the table - const tablePerms = await sdk.permissions.getResourcePerms(tableId) - await sdk.permissions.setPermissions(view.id, { - writeRole: tablePerms[PermissionLevel.WRITE].role, - readRole: tablePerms[PermissionLevel.READ].role, - }) - } + // Set permissions to be the same as the table + const tablePerms = await sdk.permissions.getResourcePerms(tableId) + await sdk.permissions.setPermissions(view.id, { + writeRole: tablePerms[PermissionLevel.WRITE].role, + readRole: tablePerms[PermissionLevel.READ].role, + }) return view } diff --git a/packages/types/src/sdk/featureFlag.ts b/packages/types/src/sdk/featureFlag.ts index 99ee0f9996..97d145db6c 100644 --- a/packages/types/src/sdk/featureFlag.ts +++ b/packages/types/src/sdk/featureFlag.ts @@ -6,7 +6,6 @@ export enum FeatureFlag { AI_CUSTOM_CONFIGS = "AI_CUSTOM_CONFIGS", DEFAULT_VALUES = "DEFAULT_VALUES", ENRICHED_RELATIONSHIPS = "ENRICHED_RELATIONSHIPS", - TABLES_DEFAULT_ADMIN = "TABLES_DEFAULT_ADMIN", BUDIBASE_AI = "BUDIBASE_AI", } From 4ef07e9c91c37498ef378a50dc130ef0081e2eb7 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 4 Nov 2024 16:59:55 +0100 Subject: [PATCH 02/22] Lint --- packages/server/src/sdk/app/tables/create.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/sdk/app/tables/create.ts b/packages/server/src/sdk/app/tables/create.ts index 1cba26fc46..0b15cdb15a 100644 --- a/packages/server/src/sdk/app/tables/create.ts +++ b/packages/server/src/sdk/app/tables/create.ts @@ -1,4 +1,4 @@ -import { FeatureFlag, Row, Table } from "@budibase/types" +import { Row, Table } from "@budibase/types" import * as external from "./external" import * as internal from "./internal" From fb760f586ae0c3abaf63abb77211d3636a8c1ee5 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 4 Nov 2024 17:03:13 +0100 Subject: [PATCH 03/22] Disable major update --- .github/workflows/tag-release.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/tag-release.yml b/.github/workflows/tag-release.yml index 483e895e98..b44395d2fe 100644 --- a/.github/workflows/tag-release.yml +++ b/.github/workflows/tag-release.yml @@ -13,7 +13,6 @@ on: options: - patch - minor - - major required: true jobs: From bbb2c20b6e80bd4583922a5f1ecf3ecb2e83143d Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 5 Nov 2024 09:35:43 +0000 Subject: [PATCH 04/22] Removed comment and debug console log --- .../automation/AutomationBuilder/DraggableCanvas.svelte | 3 --- packages/builder/src/stores/builder/automations.js | 1 - 2 files changed, 4 deletions(-) diff --git a/packages/builder/src/components/automation/AutomationBuilder/DraggableCanvas.svelte b/packages/builder/src/components/automation/AutomationBuilder/DraggableCanvas.svelte index 7a6284318f..b096c016df 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/DraggableCanvas.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/DraggableCanvas.svelte @@ -118,9 +118,6 @@ // Edge around the draggable content let contentDragPadding = 200 - // Auto scroll - // let scrollInterval - const onScale = async () => { dispatch("zoom", $view.scale) await getDims() diff --git a/packages/builder/src/stores/builder/automations.js b/packages/builder/src/stores/builder/automations.js index c7b0b9c652..8f54f85ef5 100644 --- a/packages/builder/src/stores/builder/automations.js +++ b/packages/builder/src/stores/builder/automations.js @@ -402,7 +402,6 @@ const automationActions = store => ({ traverse: (blockRefs, automation) => { let blocks = [] if (!automation || !blockRefs) { - console.error("Need a valid automation") return } if (automation.definition?.trigger) { From 94d3466113df78620dab26905ff20f4789af5622 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 5 Nov 2024 11:24:23 +0100 Subject: [PATCH 05/22] Allow setting multiple many-to-many relationships --- .../Datasources/CreateEditRelationship.svelte | 25 ++++++++----------- .../backend/Datasources/relationshipErrors.js | 6 ++--- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte index b54ecbf9fd..c8aaee0695 100644 --- a/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte +++ b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte @@ -65,7 +65,7 @@ let tableOptions let errorChecker = new RelationshipErrorChecker( invalidThroughTable, - relationshipExists + manyToManyRelationshipExistsFn ) let errors = {} let fromPrimary, fromForeign, fromColumn, toColumn @@ -125,7 +125,7 @@ } return false } - function relationshipExists() { + function manyToManyRelationshipExistsFn() { if ( originalFromTable && originalToTable && @@ -141,16 +141,14 @@ datasource.entities[getTable(toId).name].schema ).filter(value => value.through) - const matchAgainstUserInput = (fromTableId, toTableId) => - (fromTableId === fromId && toTableId === toId) || - (fromTableId === toId && toTableId === fromId) + const matchAgainstUserInput = link => + (link.throughTo === throughToKey && + link.throughFrom === throughFromKey) || + (link.throughTo === throughFromKey && link.throughFrom === throughToKey) - return !!fromThroughLinks.find(from => - toThroughLinks.find( - to => - from.through === to.through && - matchAgainstUserInput(from.tableId, to.tableId) - ) + const allLinks = [...fromThroughLinks, ...toThroughLinks] + return !!allLinks.find( + link => link.through === throughId && matchAgainstUserInput(link) ) } @@ -181,16 +179,15 @@ relationshipType: errorChecker.relationshipTypeSet(relationshipType), fromTable: errorChecker.tableSet(fromTable) || - errorChecker.doesRelationshipExists() || errorChecker.differentTables(fromId, toId, throughId), toTable: errorChecker.tableSet(toTable) || - errorChecker.doesRelationshipExists() || errorChecker.differentTables(toId, fromId, throughId), throughTable: errorChecker.throughTableSet(throughTable) || errorChecker.throughIsNullable() || - errorChecker.differentTables(throughId, fromId, toId), + errorChecker.differentTables(throughId, fromId, toId) || + errorChecker.doesRelationshipExists(), throughFromKey: errorChecker.manyForeignKeySet(throughFromKey) || errorChecker.manyTypeMismatch( diff --git a/packages/builder/src/components/backend/Datasources/relationshipErrors.js b/packages/builder/src/components/backend/Datasources/relationshipErrors.js index 610ff9f1fe..2088a55b81 100644 --- a/packages/builder/src/components/backend/Datasources/relationshipErrors.js +++ b/packages/builder/src/components/backend/Datasources/relationshipErrors.js @@ -30,9 +30,9 @@ function typeMismatchCheck(fromTable, toTable, primary, foreign) { } export class RelationshipErrorChecker { - constructor(invalidThroughTableFn, relationshipExistsFn) { + constructor(invalidThroughTableFn, manyToManyRelationshipExistsFn) { this.invalidThroughTable = invalidThroughTableFn - this.relationshipExists = relationshipExistsFn + this.manyToManyRelationshipExists = manyToManyRelationshipExistsFn } setType(type) { @@ -72,7 +72,7 @@ export class RelationshipErrorChecker { } doesRelationshipExists() { - return this.isMany() && this.relationshipExists() + return this.isMany() && this.manyToManyRelationshipExists() ? relationshipAlreadyExists : null } From 6505f518c8487249f576b3fe73f6524e252aac77 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 5 Nov 2024 11:31:46 +0100 Subject: [PATCH 06/22] Don't allow same foreign keys --- .../backend/Datasources/CreateEditRelationship.svelte | 3 ++- .../components/backend/Datasources/relationshipErrors.js | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte index c8aaee0695..8a0bcce91e 100644 --- a/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte +++ b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte @@ -195,7 +195,8 @@ throughTable, fromTable.primary[0], throughToKey - ), + ) || + errorChecker.differentColumns(throughFromKey, throughToKey), throughToKey: errorChecker.manyForeignKeySet(throughToKey) || errorChecker.manyTypeMismatch( diff --git a/packages/builder/src/components/backend/Datasources/relationshipErrors.js b/packages/builder/src/components/backend/Datasources/relationshipErrors.js index 2088a55b81..9fd30eaea2 100644 --- a/packages/builder/src/components/backend/Datasources/relationshipErrors.js +++ b/packages/builder/src/components/backend/Datasources/relationshipErrors.js @@ -3,6 +3,7 @@ import { RelationshipType } from "@budibase/types" const typeMismatch = "Column type of the foreign key must match the primary key" const columnBeingUsed = "Column name cannot be an existing column" const mustBeDifferentTables = "From/to/through tables must be different" +const mustBeDifferentColumns = "Foreign keys must be different" const primaryKeyNotSet = "Please pick the primary key" const throughNotNullable = "Ensure non-key columns are nullable or auto-generated" @@ -83,6 +84,11 @@ export class RelationshipErrorChecker { return error ? mustBeDifferentTables : null } + differentColumns(columnA, columnB) { + const error = columnA && columnB && columnA === columnB + return error ? mustBeDifferentColumns : null + } + columnBeingUsed(table, column, ogName) { return isColumnNameBeingUsed(table, column, ogName) ? columnBeingUsed : null } From e0dfc0ea10a86718bacb31ed476253941215ce75 Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 5 Nov 2024 10:48:57 +0000 Subject: [PATCH 07/22] Optional chaining for selectedAutomation --- .../AutomationBuilder/FlowChart/FlowItemHeader.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItemHeader.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItemHeader.svelte index 3e99786121..0aa43f8e04 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItemHeader.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItemHeader.svelte @@ -21,7 +21,7 @@ let editing = false const dispatch = createEventDispatcher() - $: blockRefs = $selectedAutomation.blockRefs || {} + $: blockRefs = $selectedAutomation?.blockRefs || {} $: stepNames = automation?.definition.stepNames $: allSteps = automation?.definition.steps || [] $: automationName = itemName || stepNames?.[block.id] || block?.name || "" From 3cb653eb0146e32a676d488654b8436ae03ad391 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 5 Nov 2024 11:54:09 +0100 Subject: [PATCH 08/22] Fix initial setup --- .../backend/Datasources/CreateEditRelationship.svelte | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte index 8a0bcce91e..7e11c98768 100644 --- a/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte +++ b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte @@ -370,6 +370,16 @@ fromColumn = selectedFromTable.name fromPrimary = selectedFromTable?.primary[0] || null } + if (relationshipType === RelationshipType.MANY_TO_MANY) { + relationshipPart1 = PrettyRelationshipDefinitions.MANY + relationshipPart2 = PrettyRelationshipDefinitions.MANY + } else if (relationshipType === RelationshipType.MANY_TO_ONE) { + relationshipPart1 = PrettyRelationshipDefinitions.ONE + relationshipPart2 = PrettyRelationshipDefinitions.MANY + } else { + relationshipPart1 = PrettyRelationshipDefinitions.MANY + relationshipPart2 = PrettyRelationshipDefinitions.ONE + } }) From 7623c0ce079c3821324dae036c646afc7a74fc8e Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 5 Nov 2024 10:54:33 +0000 Subject: [PATCH 09/22] further AI config updates for case where there's no configuration --- .../builder/portal/settings/ai/index.svelte | 5 ++-- .../builder/portal/settings/index.svelte | 4 +-- packages/pro | 2 +- .../server/src/automations/steps/openai.ts | 18 +++++-------- .../src/utilities/rowProcessor/utils.ts | 2 +- .../src/api/controllers/global/configs.ts | 25 +++++++++++++------ 6 files changed, 31 insertions(+), 25 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/settings/ai/index.svelte b/packages/builder/src/pages/builder/portal/settings/ai/index.svelte index bbdf46a24e..ec0ff31e58 100644 --- a/packages/builder/src/pages/builder/portal/settings/ai/index.svelte +++ b/packages/builder/src/pages/builder/portal/settings/ai/index.svelte @@ -12,7 +12,7 @@ Tags, Tag, } from "@budibase/bbui" - import { admin, licensing } from "stores/portal" + import { admin, licensing, featureFlags } from "stores/portal" import { API } from "api" import AIConfigModal from "./ConfigModal.svelte" import AIConfigTile from "./AIConfigTile.svelte" @@ -27,7 +27,8 @@ let editingUuid $: isCloud = $admin.cloud - $: customAIConfigsEnabled = $licensing.customAIConfigsEnabled + $: customAIConfigsEnabled = + $featureFlags.AI_CUSTOM_CONFIGS && $licensing.customAIConfigsEnabled async function fetchAIConfig() { try { diff --git a/packages/builder/src/pages/builder/portal/settings/index.svelte b/packages/builder/src/pages/builder/portal/settings/index.svelte index 1448b43ec4..26688e3861 100644 --- a/packages/builder/src/pages/builder/portal/settings/index.svelte +++ b/packages/builder/src/pages/builder/portal/settings/index.svelte @@ -1,8 +1,8 @@