From 62ee1aad8b291e32b6964a5055fed504c234a9f9 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Tue, 17 Sep 2024 16:14:33 +0530 Subject: [PATCH] fix: apply view based filter if linkColumnId present (#9500) --- .../old-datas/old-datas.service.ts | 2 +- .../public-datas-export.controller.ts | 2 +- packages/nocodb/src/helpers/dataHelpers.ts | 3 ++- .../src/modules/auth/auth.controller.ts | 9 +++++-- .../nocodb/src/services/data-table.service.ts | 2 +- packages/nocodb/src/services/datas.service.ts | 26 +++++++++++++++++-- .../src/services/public-datas.service.ts | 2 +- 7 files changed, 37 insertions(+), 9 deletions(-) diff --git a/packages/nocodb/src/controllers/old-datas/old-datas.service.ts b/packages/nocodb/src/controllers/old-datas/old-datas.service.ts index d312d32263..ca5bdf994c 100644 --- a/packages/nocodb/src/controllers/old-datas/old-datas.service.ts +++ b/packages/nocodb/src/controllers/old-datas/old-datas.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@nestjs/common'; -import { nocoExecute } from '~/utils'; import type { OldPathParams } from '~/helpers/dataHelpers'; import type { NcContext } from '~/interface/config'; +import { nocoExecute } from '~/utils'; import getAst from '~/helpers/getAst'; import { NcError } from '~/helpers/catchError'; import { Base, Model, Source, View } from '~/models'; diff --git a/packages/nocodb/src/controllers/public-datas-export.controller.ts b/packages/nocodb/src/controllers/public-datas-export.controller.ts index d0c5a1ebbe..b5a1cc3705 100644 --- a/packages/nocodb/src/controllers/public-datas-export.controller.ts +++ b/packages/nocodb/src/controllers/public-datas-export.controller.ts @@ -8,8 +8,8 @@ import { } from '@nestjs/common'; import { isSystemColumn, ViewTypes } from 'nocodb-sdk'; import * as XLSX from 'xlsx'; -import { nocoExecute } from '~/utils'; import papaparse from 'papaparse'; +import { nocoExecute } from '~/utils'; import { NcError } from '~/helpers/catchError'; import getAst from '~/helpers/getAst'; import { serializeCellValue } from '~/helpers/dataHelpers'; diff --git a/packages/nocodb/src/helpers/dataHelpers.ts b/packages/nocodb/src/helpers/dataHelpers.ts index 15d2960eaf..161a0eb725 100644 --- a/packages/nocodb/src/helpers/dataHelpers.ts +++ b/packages/nocodb/src/helpers/dataHelpers.ts @@ -1,4 +1,3 @@ -import { nocoExecute } from '~/utils'; import { isSystemColumn, UITypes } from 'nocodb-sdk'; import * as XLSX from 'xlsx'; import papaparse from 'papaparse'; @@ -6,6 +5,7 @@ import type { BaseModelSqlv2 } from '~/db/BaseModelSqlv2'; import type LinkToAnotherRecordColumn from '~/models/LinkToAnotherRecordColumn'; import type LookupColumn from '~/models/LookupColumn'; import type { NcContext } from '~/interface/config'; +import { nocoExecute } from '~/utils'; import { NcError } from '~/helpers/catchError'; import getAst from '~/helpers/getAst'; import { Model, View } from '~/models'; @@ -50,6 +50,7 @@ export async function getViewAndModelByAliasOrId( fk_model_id: model.id, })); if (param.viewName && !view) NcError.viewNotFound(param.viewName); + return { model, view }; } diff --git a/packages/nocodb/src/modules/auth/auth.controller.ts b/packages/nocodb/src/modules/auth/auth.controller.ts index 6c121ce7f4..3d880d86d4 100644 --- a/packages/nocodb/src/modules/auth/auth.controller.ts +++ b/packages/nocodb/src/modules/auth/auth.controller.ts @@ -93,7 +93,7 @@ export class AuthController { } @UseGuards(GlobalGuard) - @Post(['/api/v1/auth/user/signout','/api/v2/auth/user/signout']) + @Post(['/api/v1/auth/user/signout', '/api/v2/auth/user/signout']) @HttpCode(200) async signOut(@Req() req: NcRequest, @Res() res: Response): Promise { if (!(req as any).isAuthenticated?.()) { @@ -121,7 +121,12 @@ export class AuthController { // google strategy will take care the request } - @Get(['/auth/user/me', '/api/v1/db/auth/user/me', '/api/v1/auth/user/me', '/api/v2/auth/user/me']) + @Get([ + '/auth/user/me', + '/api/v1/db/auth/user/me', + '/api/v1/auth/user/me', + '/api/v2/auth/user/me', + ]) @UseGuards(MetaApiLimiterGuard, GlobalGuard) async me(@Req() req: NcRequest) { const user = { diff --git a/packages/nocodb/src/services/data-table.service.ts b/packages/nocodb/src/services/data-table.service.ts index fe91429321..1671bfda41 100644 --- a/packages/nocodb/src/services/data-table.service.ts +++ b/packages/nocodb/src/services/data-table.service.ts @@ -1,9 +1,9 @@ import { Injectable } from '@nestjs/common'; import { isLinksOrLTAR, RelationTypes, ViewTypes } from 'nocodb-sdk'; -import { nocoExecute } from '~/utils'; import { validatePayload } from 'src/helpers'; import type { LinkToAnotherRecordColumn } from '~/models'; import type { NcContext } from '~/interface/config'; +import { nocoExecute } from '~/utils'; import { Column, Model, Source, View } from '~/models'; import { DatasService } from '~/services/datas.service'; import { NcError } from '~/helpers/catchError'; diff --git a/packages/nocodb/src/services/datas.service.ts b/packages/nocodb/src/services/datas.service.ts index f917c4be2d..0894a1c05a 100644 --- a/packages/nocodb/src/services/datas.service.ts +++ b/packages/nocodb/src/services/datas.service.ts @@ -1,12 +1,13 @@ import { Injectable, Logger } from '@nestjs/common'; -import { isSystemColumn } from 'nocodb-sdk'; +import { isLinksOrLTAR, isSystemColumn } from 'nocodb-sdk'; import * as XLSX from 'xlsx'; import papaparse from 'papaparse'; -import { nocoExecute } from '~/utils'; import type { BaseModelSqlv2 } from '~/db/BaseModelSqlv2'; import type { PathParams } from '~/helpers/dataHelpers'; import type { NcContext } from '~/interface/config'; import type { Filter } from '~/models'; +import type LinkToAnotherRecordColumn from '../models/LinkToAnotherRecordColumn'; +import { nocoExecute } from '~/utils'; import { getDbRows, getViewAndModelByAliasOrId } from '~/helpers/dataHelpers'; import { Base, Column, Model, Source, View } from '~/models'; import { NcBaseError, NcError } from '~/helpers/catchError'; @@ -41,6 +42,27 @@ export class DatasService { view = modelAndView.view; } + // check for linkColumnId query param and handle it + if (param.query.linkColumnId) { + const linkColumn = await Column.get(context, { + colId: param.query.linkColumnId, + }); + + if ( + !linkColumn || + !isLinksOrLTAR(linkColumn) || + linkColumn.colOptions.fk_related_model_id !== model.id + ) { + NcError.fieldNotFound(param.query?.linkColumnId, { + customMessage: `Link column with id ${param.query.linkColumnId} not found`, + }); + } + + if (linkColumn.colOptions.fk_target_view_id) { + view = await View.get(context, linkColumn.colOptions.fk_target_view_id); + } + } + return await this.getDataList(context, { model, view, diff --git a/packages/nocodb/src/services/public-datas.service.ts b/packages/nocodb/src/services/public-datas.service.ts index 099d08cd32..0aba33ef4b 100644 --- a/packages/nocodb/src/services/public-datas.service.ts +++ b/packages/nocodb/src/services/public-datas.service.ts @@ -1,8 +1,8 @@ import { forwardRef, Inject, Injectable } from '@nestjs/common'; import { UITypes, ViewTypes } from 'nocodb-sdk'; -import { nocoExecute } from '~/utils'; import type { LinkToAnotherRecordColumn } from '~/models'; import type { NcContext } from '~/interface/config'; +import { nocoExecute } from '~/utils'; import { Column, Model, Source, View } from '~/models'; import { NcError } from '~/helpers/catchError'; import getAst from '~/helpers/getAst';