From b0debf17ef1c3faba4bcc4db67b9bc9de67b12b9 Mon Sep 17 00:00:00 2001 From: melohagan <101575380+melohagan@users.noreply.github.com> Date: Tue, 20 Jun 2023 17:07:12 +0100 Subject: [PATCH 1/3] Table disappears from side bar when changing display name (#10909) * Pass sourceId on fetch tables * Use ExternalTable type --- .../server/src/integrations/googlesheets.ts | 22 ++++++++++++++----- .../src/integrations/microsoftSqlServer.ts | 12 ++++++---- packages/server/src/integrations/mysql.ts | 12 ++++++---- packages/server/src/integrations/oracle.ts | 12 ++++++---- packages/server/src/integrations/postgres.ts | 12 ++++++---- packages/types/src/documents/app/table.ts | 4 ++++ 6 files changed, 52 insertions(+), 22 deletions(-) diff --git a/packages/server/src/integrations/googlesheets.ts b/packages/server/src/integrations/googlesheets.ts index 8863aa0b3a..819d34ffd2 100644 --- a/packages/server/src/integrations/googlesheets.ts +++ b/packages/server/src/integrations/googlesheets.ts @@ -12,7 +12,7 @@ import { Row, SearchFilters, SortJson, - Table, + ExternalTable, TableRequest, } from "@budibase/types" import { OAuth2Client } from "google-auth-library" @@ -136,7 +136,7 @@ const SCHEMA: Integration = { class GoogleSheetsIntegration implements DatasourcePlus { private readonly config: GoogleSheetsConfig private client: GoogleSpreadsheet - public tables: Record = {} + public tables: Record = {} public schemaErrors: Record = {} constructor(config: GoogleSheetsConfig) { @@ -248,12 +248,18 @@ class GoogleSheetsIntegration implements DatasourcePlus { return sheets.map(s => s.title) } - getTableSchema(title: string, headerValues: string[], id?: string) { + getTableSchema( + title: string, + headerValues: string[], + datasourceId: string, + id?: string + ) { // base table - const table: Table = { + const table: ExternalTable = { name: title, primary: [GOOGLE_SHEETS_PRIMARY_KEY], schema: {}, + sourceId: datasourceId, } if (id) { table._id = id @@ -268,14 +274,17 @@ class GoogleSheetsIntegration implements DatasourcePlus { return table } - async buildSchema(datasourceId: string, entities: Record) { + async buildSchema( + datasourceId: string, + entities: Record + ) { // not fully configured yet if (!this.config.auth) { return } await this.connect() const sheets = this.client.sheetsByIndex - const tables: Record = {} + const tables: Record = {} for (let sheet of sheets) { // must fetch rows to determine schema await sheet.getRows() @@ -284,6 +293,7 @@ class GoogleSheetsIntegration implements DatasourcePlus { tables[sheet.title] = this.getTableSchema( sheet.title, sheet.headerValues, + datasourceId, id ) } diff --git a/packages/server/src/integrations/microsoftSqlServer.ts b/packages/server/src/integrations/microsoftSqlServer.ts index 291aad8631..56e309bc6a 100644 --- a/packages/server/src/integrations/microsoftSqlServer.ts +++ b/packages/server/src/integrations/microsoftSqlServer.ts @@ -2,7 +2,7 @@ import { DatasourceFieldType, Integration, Operation, - Table, + ExternalTable, TableSchema, QueryJson, QueryType, @@ -97,7 +97,7 @@ class SqlServerIntegration extends Sql implements DatasourcePlus { private index: number = 0 private readonly pool: any private client: any - public tables: Record = {} + public tables: Record = {} public schemaErrors: Record = {} MASTER_TABLES = [ @@ -220,7 +220,10 @@ class SqlServerIntegration extends Sql implements DatasourcePlus { * @param {*} datasourceId - datasourceId to fetch * @param entities - the tables that are to be built */ - async buildSchema(datasourceId: string, entities: Record) { + async buildSchema( + datasourceId: string, + entities: Record + ) { await this.connect() let tableInfo: MSSQLTablesResponse[] = await this.runSQL(this.TABLES_SQL) if (tableInfo == null || !Array.isArray(tableInfo)) { @@ -233,7 +236,7 @@ class SqlServerIntegration extends Sql implements DatasourcePlus { .map((record: any) => record.TABLE_NAME) .filter((name: string) => this.MASTER_TABLES.indexOf(name) === -1) - const tables: Record = {} + const tables: Record = {} for (let tableName of tableNames) { // get the column definition (type) const definition = await this.runSQL(this.getDefinitionSQL(tableName)) @@ -276,6 +279,7 @@ class SqlServerIntegration extends Sql implements DatasourcePlus { } tables[tableName] = { _id: buildExternalTableId(datasourceId, tableName), + sourceId: datasourceId, primary: primaryKeys, name: tableName, schema, diff --git a/packages/server/src/integrations/mysql.ts b/packages/server/src/integrations/mysql.ts index c3bb5e066f..faac3170db 100644 --- a/packages/server/src/integrations/mysql.ts +++ b/packages/server/src/integrations/mysql.ts @@ -4,7 +4,7 @@ import { QueryType, QueryJson, SqlQuery, - Table, + ExternalTable, TableSchema, DatasourcePlus, DatasourceFeature, @@ -123,7 +123,7 @@ export function bindingTypeCoerce(bindings: any[]) { class MySQLIntegration extends Sql implements DatasourcePlus { private config: MySQLConfig private client?: mysql.Connection - public tables: Record = {} + public tables: Record = {} public schemaErrors: Record = {} constructor(config: MySQLConfig) { @@ -220,8 +220,11 @@ class MySQLIntegration extends Sql implements DatasourcePlus { } } - async buildSchema(datasourceId: string, entities: Record) { - const tables: { [key: string]: Table } = {} + async buildSchema( + datasourceId: string, + entities: Record + ) { + const tables: { [key: string]: ExternalTable } = {} await this.connect() try { @@ -259,6 +262,7 @@ class MySQLIntegration extends Sql implements DatasourcePlus { if (!tables[tableName]) { tables[tableName] = { _id: buildExternalTableId(datasourceId, tableName), + sourceId: datasourceId, primary: primaryKeys, name: tableName, schema, diff --git a/packages/server/src/integrations/oracle.ts b/packages/server/src/integrations/oracle.ts index d8c366814f..3e8ec15423 100644 --- a/packages/server/src/integrations/oracle.ts +++ b/packages/server/src/integrations/oracle.ts @@ -5,7 +5,7 @@ import { QueryJson, QueryType, SqlQuery, - Table, + ExternalTable, DatasourcePlus, DatasourceFeature, ConnectionInfo, @@ -108,7 +108,7 @@ class OracleIntegration extends Sql implements DatasourcePlus { private readonly config: OracleConfig private index: number = 1 - public tables: Record = {} + public tables: Record = {} public schemaErrors: Record = {} private readonly COLUMNS_SQL = ` @@ -262,13 +262,16 @@ class OracleIntegration extends Sql implements DatasourcePlus { * @param {*} datasourceId - datasourceId to fetch * @param entities - the tables that are to be built */ - async buildSchema(datasourceId: string, entities: Record) { + async buildSchema( + datasourceId: string, + entities: Record + ) { const columnsResponse = await this.internalQuery({ sql: this.COLUMNS_SQL, }) const oracleTables = this.mapColumns(columnsResponse) - const tables: { [key: string]: Table } = {} + const tables: { [key: string]: ExternalTable } = {} // iterate each table Object.values(oracleTables).forEach(oracleTable => { @@ -279,6 +282,7 @@ class OracleIntegration extends Sql implements DatasourcePlus { primary: [], name: oracleTable.name, schema: {}, + sourceId: datasourceId, } tables[oracleTable.name] = table } diff --git a/packages/server/src/integrations/postgres.ts b/packages/server/src/integrations/postgres.ts index 47295716e6..3f7c11158a 100644 --- a/packages/server/src/integrations/postgres.ts +++ b/packages/server/src/integrations/postgres.ts @@ -4,7 +4,7 @@ import { QueryType, QueryJson, SqlQuery, - Table, + ExternalTable, DatasourcePlus, DatasourceFeature, ConnectionInfo, @@ -124,7 +124,7 @@ class PostgresIntegration extends Sql implements DatasourcePlus { private readonly config: PostgresConfig private index: number = 1 private open: boolean - public tables: Record = {} + public tables: Record = {} public schemaErrors: Record = {} COLUMNS_SQL!: string @@ -239,7 +239,10 @@ class PostgresIntegration extends Sql implements DatasourcePlus { * @param {*} datasourceId - datasourceId to fetch * @param entities - the tables that are to be built */ - async buildSchema(datasourceId: string, entities: Record) { + async buildSchema( + datasourceId: string, + entities: Record + ) { let tableKeys: { [key: string]: string[] } = {} await this.openConnection() try { @@ -265,7 +268,7 @@ class PostgresIntegration extends Sql implements DatasourcePlus { const columnsResponse: { rows: PostgresColumn[] } = await this.client.query(this.COLUMNS_SQL) - const tables: { [key: string]: Table } = {} + const tables: { [key: string]: ExternalTable } = {} for (let column of columnsResponse.rows) { const tableName: string = column.table_name @@ -278,6 +281,7 @@ class PostgresIntegration extends Sql implements DatasourcePlus { primary: tableKeys[tableName] || [], name: tableName, schema: {}, + sourceId: datasourceId, } } diff --git a/packages/types/src/documents/app/table.ts b/packages/types/src/documents/app/table.ts index 849009098b..7089709808 100644 --- a/packages/types/src/documents/app/table.ts +++ b/packages/types/src/documents/app/table.ts @@ -82,6 +82,10 @@ export interface Table extends Document { rowHeight?: number } +export interface ExternalTable extends Table { + sourceId: string +} + export interface TableRequest extends Table { _rename?: RenameColumn created?: boolean From 9e9cece59e417dc6ccbd8bc4dc5fe54fbde91993 Mon Sep 17 00:00:00 2001 From: melohagan <101575380+melohagan@users.noreply.github.com> Date: Tue, 20 Jun 2023 17:07:34 +0100 Subject: [PATCH 2/3] Clone user (#10974) --- packages/server/src/utilities/global.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/server/src/utilities/global.ts b/packages/server/src/utilities/global.ts index 93b7fc1207..8366794b18 100644 --- a/packages/server/src/utilities/global.ts +++ b/packages/server/src/utilities/global.ts @@ -9,7 +9,7 @@ import { import env from "../environment" import { groups } from "@budibase/pro" import { UserCtx, ContextUser, User, UserGroup } from "@budibase/types" -import { global } from "yargs" +import { cloneDeep } from "lodash" export function updateAppRole( user: ContextUser, @@ -65,16 +65,20 @@ export async function processUser( user: ContextUser, opts: { appId?: string; groups?: UserGroup[] } = {} ) { - if (user) { - delete user.password + let clonedUser = cloneDeep(user) + if (clonedUser) { + delete clonedUser.password } const appId = opts.appId || context.getAppId() - user = updateAppRole(user, { appId }) - if (!user.roleId && user?.userGroups?.length) { - user = await checkGroupRoles(user, { appId, groups: opts?.groups }) + clonedUser = updateAppRole(clonedUser, { appId }) + if (!clonedUser.roleId && clonedUser?.userGroups?.length) { + clonedUser = await checkGroupRoles(clonedUser, { + appId, + groups: opts?.groups, + }) } - return user + return clonedUser } export async function getCachedSelf(ctx: UserCtx, appId: string) { From b491eb36a532d91faced8a84da6e46edd36f585d Mon Sep 17 00:00:00 2001 From: Budibase Staging Release Bot <> Date: Tue, 20 Jun 2023 16:14:40 +0000 Subject: [PATCH 3/3] Bump version to 2.7.25 --- lerna.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lerna.json b/lerna.json index 86de1e4387..9addf2b7c9 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "2.7.24", + "version": "2.7.25", "npmClient": "yarn", "packages": [ "packages/backend-core",