mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-23 08:58:26 +00:00
Fix: Removed the org id from the query option details of the ToolJet database. (#10303)
* fix: removed orgid from query options and updated dependent logic in tjdb operations service as well * fix: On exporting tjdb table schema only tables used for respective operation is filtered and validated now it will not pick from join options json even if it is available for list row operation
This commit is contained in:
parent
744b6b0d18
commit
adacfbe48c
4 changed files with 35 additions and 21 deletions
|
|
@ -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(() => {
|
||||
|
|
|
|||
|
|
@ -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 }));
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -17,19 +17,25 @@ export class TooljetDbOperationsService implements QueryService {
|
|||
private readonly manager: EntityManager
|
||||
) {}
|
||||
|
||||
async run(_sourceOptions, queryOptions, _dataSourceCacheId, _dataSourceCacheUpdatedAt): Promise<QueryResult> {
|
||||
async run(
|
||||
_sourceOptions,
|
||||
queryOptions,
|
||||
_dataSourceCacheId,
|
||||
_dataSourceCacheUpdatedAt,
|
||||
context
|
||||
): Promise<QueryResult> {
|
||||
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<QueryResult> {
|
||||
async listRows(queryOptions, context): Promise<QueryResult> {
|
||||
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<QueryResult> {
|
||||
async createRow(queryOptions, context): Promise<QueryResult> {
|
||||
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<QueryResult> {
|
||||
async updateRows(queryOptions, context): Promise<QueryResult> {
|
||||
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<QueryResult> {
|
||||
async deleteRows(queryOptions, context): Promise<QueryResult> {
|
||||
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<QueryResult> {
|
||||
const organizationId = queryOptions.organization_id;
|
||||
async joinTables(queryOptions, context): Promise<QueryResult> {
|
||||
const { organization_id: organizationId } = context.app;
|
||||
const { join_table = {} } = queryOptions;
|
||||
|
||||
// Empty Input is restricted
|
||||
|
|
|
|||
Loading…
Reference in a new issue