Browse Source

fix: apply view based filter if linkColumnId present (#9500)

pull/9502/head
Pranav C 2 months ago committed by GitHub
parent
commit
62ee1aad8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      packages/nocodb/src/controllers/old-datas/old-datas.service.ts
  2. 2
      packages/nocodb/src/controllers/public-datas-export.controller.ts
  3. 3
      packages/nocodb/src/helpers/dataHelpers.ts
  4. 9
      packages/nocodb/src/modules/auth/auth.controller.ts
  5. 2
      packages/nocodb/src/services/data-table.service.ts
  6. 26
      packages/nocodb/src/services/datas.service.ts
  7. 2
      packages/nocodb/src/services/public-datas.service.ts

2
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';

2
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';

3
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 };
}

9
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<any> {
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 = {

2
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';

26
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<LinkToAnotherRecordColumn>(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,

2
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';

Loading…
Cancel
Save