diff --git a/frontend/src/Editor/QueryManager/QueryEditors/TooljetDatabase/ToolJetDbOperations.jsx b/frontend/src/Editor/QueryManager/QueryEditors/TooljetDatabase/ToolJetDbOperations.jsx index 61076fe1a1..1a69efc978 100644 --- a/frontend/src/Editor/QueryManager/QueryEditors/TooljetDatabase/ToolJetDbOperations.jsx +++ b/frontend/src/Editor/QueryManager/QueryEditors/TooljetDatabase/ToolJetDbOperations.jsx @@ -436,7 +436,6 @@ const ToolJetDbOperations = ({ optionchanged, options, darkMode, isHorizontalLay const handleTableNameSelect = (tableId) => { setSelectedTableId(tableId); fetchTableInformation(tableId, true, tables); - optionchanged('organization_id', organizationId); optionchanged('table_id', tableId); setJoinTableOptions(() => { diff --git a/frontend/src/HomePage/ExportAppModal.jsx b/frontend/src/HomePage/ExportAppModal.jsx index 37ee59e851..5049240453 100644 --- a/frontend/src/HomePage/ExportAppModal.jsx +++ b/frontend/src/HomePage/ExportAppModal.jsx @@ -50,7 +50,7 @@ export default function ExportAppModal({ title, show, closeModal, customClassNam const { dataQueries } = tbl; const extractedIdData = []; dataQueries.forEach((item) => { - if (item.kind === 'tooljetdb') { + if (item.kind === 'tooljetdb' && item.options?.operation === 'join_tables') { const joinOptions = item.options?.join_table?.joins ?? []; (joinOptions || []).forEach((join) => { const { table, conditions } = join; @@ -66,6 +66,8 @@ export default function ExportAppModal({ title, show, closeModal, customClassNam }); }); } + + if (item.kind === 'tooljetdb' && item.options.table_id) extractedIdData.push(item.options.table_id); }); const uniqueSet = new Set(extractedIdData); const selectedVersiontable = Array.from(uniqueSet).map((item) => ({ table_id: item })); diff --git a/server/src/services/data_queries.service.ts b/server/src/services/data_queries.service.ts index 7775cd4fd3..f4f19c7855 100644 --- a/server/src/services/data_queries.service.ts +++ b/server/src/services/data_queries.service.ts @@ -185,7 +185,11 @@ export class DataQueriesService { dataSourceOptions.updatedAt, { user: { id: user?.id }, - app: { id: app?.id, isPublic: app?.isPublic }, + app: { + id: app?.id, + isPublic: app?.isPublic, + ...(dataSource.kind === 'tooljetdb' && { organization_id: app.organizationId }), + }, } ); } catch (api_error) { diff --git a/server/src/services/tooljet_db_operations.service.ts b/server/src/services/tooljet_db_operations.service.ts index b3944a0e37..6622427822 100644 --- a/server/src/services/tooljet_db_operations.service.ts +++ b/server/src/services/tooljet_db_operations.service.ts @@ -17,19 +17,25 @@ export class TooljetDbOperationsService implements QueryService { private readonly manager: EntityManager ) {} - async run(_sourceOptions, queryOptions, _dataSourceCacheId, _dataSourceCacheUpdatedAt): Promise { + async run( + _sourceOptions, + queryOptions, + _dataSourceCacheId, + _dataSourceCacheUpdatedAt, + context + ): Promise { switch (queryOptions.operation) { case 'list_rows': - return this.listRows(queryOptions); + return this.listRows(queryOptions, context); case 'create_row': - return this.createRow(queryOptions); + return this.createRow(queryOptions, context); case 'update_rows': - return this.updateRows(queryOptions); + return this.updateRows(queryOptions, context); case 'delete_rows': - return this.deleteRows(queryOptions); + return this.deleteRows(queryOptions, context); case 'join_tables': // custom implementation without PostgREST - return this.joinTables(queryOptions); + return this.joinTables(queryOptions, context); default: return { @@ -51,7 +57,7 @@ export class TooljetDbOperationsService implements QueryService { return { status: 'ok', data: result }; } - async listRows(queryOptions): Promise { + async listRows(queryOptions, context): Promise { if (hasNullValueInFilters(queryOptions, 'list_rows')) { return { status: 'failed', @@ -60,7 +66,8 @@ export class TooljetDbOperationsService implements QueryService { }; } try { - const { table_id: tableId, list_rows: listRows, organization_id: organizationId } = queryOptions; + const { table_id: tableId, list_rows: listRows } = queryOptions; + const { organization_id: organizationId } = context.app; const query = []; if (!isEmpty(listRows)) { @@ -106,7 +113,7 @@ export class TooljetDbOperationsService implements QueryService { !isEmpty(offset) && query.push(`offset=${offset}`); } - const headers = { 'data-query-id': queryOptions.id, 'tj-workspace-id': queryOptions.organization_id }; + const headers = { 'data-query-id': queryOptions.id, 'tj-workspace-id': organizationId }; const url = query.length > 0 ? `/api/tooljet-db/proxy/${tableId}` + `?${query.join('&')}` @@ -118,19 +125,19 @@ export class TooljetDbOperationsService implements QueryService { } } - async createRow(queryOptions): Promise { + async createRow(queryOptions, context): Promise { const columns = Object.values(queryOptions.create_row).reduce((acc, colOpts: { column: string; value: any }) => { if (isEmpty(colOpts.column)) return acc; return Object.assign(acc, { [colOpts.column]: colOpts.value }); }, {}); - - const headers = { 'data-query-id': queryOptions.id, 'tj-workspace-id': queryOptions.organization_id }; + const { organization_id: organizationId } = context.app; + const headers = { 'data-query-id': queryOptions.id, 'tj-workspace-id': organizationId }; const url = maybeSetSubPath(`/api/tooljet-db/proxy/${queryOptions.table_id}`); return await this.proxyPostgrest(url, 'POST', headers, columns); } - async updateRows(queryOptions): Promise { + async updateRows(queryOptions, context): Promise { if (hasNullValueInFilters(queryOptions, 'update_rows')) { return { status: 'failed', @@ -140,6 +147,7 @@ export class TooljetDbOperationsService implements QueryService { } const { table_id: tableId, update_rows: updateRows } = queryOptions; const { where_filters: whereFilters, columns } = updateRows; + const { organization_id: organizationId } = context.app; const query = []; const whereQuery = buildPostgrestQuery(whereFilters); @@ -150,12 +158,12 @@ export class TooljetDbOperationsService implements QueryService { !isEmpty(whereQuery) && query.push(whereQuery); - const headers = { 'data-query-id': queryOptions.id, 'tj-workspace-id': queryOptions.organization_id }; + const headers = { 'data-query-id': queryOptions.id, 'tj-workspace-id': organizationId }; const url = maybeSetSubPath(`/api/tooljet-db/proxy/${tableId}?` + query.join('&') + '&order=id'); return await this.proxyPostgrest(url, 'PATCH', headers, body); } - async deleteRows(queryOptions): Promise { + async deleteRows(queryOptions, context): Promise { if (hasNullValueInFilters(queryOptions, 'delete_rows')) { return { status: 'failed', @@ -165,6 +173,7 @@ export class TooljetDbOperationsService implements QueryService { } const { table_id: tableId, delete_rows: deleteRows = { whereFilters: {} } } = queryOptions; const { where_filters: whereFilters, limit = 1 } = deleteRows; + const { organization_id: organizationId } = context.app; const query = []; const whereQuery = buildPostgrestQuery(whereFilters); @@ -187,13 +196,13 @@ export class TooljetDbOperationsService implements QueryService { !isEmpty(whereQuery) && query.push(whereQuery); limit && limit !== '' && query.push(`limit=${limit}&order=id`); - const headers = { 'data-query-id': queryOptions.id, 'tj-workspace-id': queryOptions.organization_id }; + const headers = { 'data-query-id': queryOptions.id, 'tj-workspace-id': organizationId }; const url = maybeSetSubPath(`/api/tooljet-db/proxy/${tableId}?` + query.join('&')); return await this.proxyPostgrest(url, 'DELETE', headers); } - async joinTables(queryOptions): Promise { - const organizationId = queryOptions.organization_id; + async joinTables(queryOptions, context): Promise { + const { organization_id: organizationId } = context.app; const { join_table = {} } = queryOptions; // Empty Input is restricted