Browse Source

refactor: proper custom request type in service and other files

pull/6914/head
Pranav C 1 year ago
parent
commit
d61424c3e6
  1. 3
      packages/nocodb/src/guards/global/global.guard.ts
  2. 5
      packages/nocodb/src/helpers/catchError.ts
  3. 5
      packages/nocodb/src/interface/config.ts
  4. 7
      packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts
  5. 3
      packages/nocodb/src/modules/jobs/jobs/meta-sync/meta-sync.processor.ts
  6. 5
      packages/nocodb/src/services/api-tokens.service.ts
  7. 2
      packages/nocodb/src/services/app-hooks/interfaces.ts
  8. 5
      packages/nocodb/src/services/attachments.service.ts
  9. 3
      packages/nocodb/src/services/base-users/base-users.service.ts
  10. 11
      packages/nocodb/src/services/bases.service.ts
  11. 5
      packages/nocodb/src/services/columns.service.ts
  12. 9
      packages/nocodb/src/services/filters.service.ts
  13. 3
      packages/nocodb/src/services/form-columns.service.ts
  14. 5
      packages/nocodb/src/services/forms.service.ts
  15. 5
      packages/nocodb/src/services/galleries.service.ts
  16. 3
      packages/nocodb/src/services/grid-columns.service.ts
  17. 5
      packages/nocodb/src/services/grids.service.ts
  18. 9
      packages/nocodb/src/services/hooks.service.ts
  19. 5
      packages/nocodb/src/services/kanbans.service.ts
  20. 5
      packages/nocodb/src/services/maps.service.ts
  21. 3
      packages/nocodb/src/services/model-visibilities.service.ts
  22. 3
      packages/nocodb/src/services/notifications.service.ts
  23. 5
      packages/nocodb/src/services/org-tokens.service.ts
  24. 5
      packages/nocodb/src/services/org-users.service.ts
  25. 5
      packages/nocodb/src/services/plugins.service.ts
  26. 8
      packages/nocodb/src/services/shared-bases.service.ts
  27. 7
      packages/nocodb/src/services/sorts.service.ts
  28. 7
      packages/nocodb/src/services/sources.service.ts
  29. 7
      packages/nocodb/src/services/sync.service.ts
  30. 3
      packages/nocodb/src/services/tables.service.ts
  31. 11
      packages/nocodb/src/services/users/users.service.ts
  32. 5
      packages/nocodb/src/services/view-columns.service.ts
  33. 15
      packages/nocodb/src/services/views.service.ts
  34. 3
      packages/nocodb/src/strategies/authtoken.strategy/authtoken.strategy.ts
  35. 4
      packages/nocodb/src/strategies/base-view.strategy/base-view.strategy.ts
  36. 5
      packages/nocodb/src/strategies/google.strategy/google.strategy.ts
  37. 8
      packages/nocodb/src/types/express.d.ts

3
packages/nocodb/src/guards/global/global.guard.ts

@ -4,6 +4,7 @@ import { lastValueFrom, Observable } from 'rxjs';
import { extractRolesObj } from 'nocodb-sdk'; import { extractRolesObj } from 'nocodb-sdk';
import type { ExecutionContext } from '@nestjs/common'; import type { ExecutionContext } from '@nestjs/common';
import { JwtStrategy } from '~/strategies/jwt.strategy'; import { JwtStrategy } from '~/strategies/jwt.strategy';
import {Request} from 'express'
@Injectable() @Injectable()
export class GlobalGuard extends AuthGuard(['jwt']) { export class GlobalGuard extends AuthGuard(['jwt']) {
@ -75,7 +76,7 @@ export class GlobalGuard extends AuthGuard(['jwt']) {
} }
private async authenticate( private async authenticate(
req: any, req: Request,
user: any = { user: any = {
roles: { roles: {
guest: true, guest: true,

5
packages/nocodb/src/helpers/catchError.ts

@ -1,4 +1,5 @@
import type { ErrorObject } from 'ajv'; import type { ErrorObject } from 'ajv';
import {NextFunction,Request,Response} from "express";
export enum DBError { export enum DBError {
TABLE_EXIST = 'TABLE_EXIST', TABLE_EXIST = 'TABLE_EXIST',
@ -384,9 +385,9 @@ export function extractDBError(error): {
} }
export default function ( export default function (
requestHandler: (req: any, res: any, next?: any) => any, requestHandler: (req: Request, res: Response, next?: NextFunction) => any,
) { ) {
return async function (req: any, res: any, next: any) { return async function (req: Request, res: Response, next?: NextFunction) {
try { try {
return await requestHandler(req, res, next); return await requestHandler(req, res, next);
} catch (e) { } catch (e) {

5
packages/nocodb/src/interface/config.ts

@ -2,6 +2,8 @@ import type { ReqId } from 'pino-http';
import type { Handler } from 'express'; import type { Handler } from 'express';
import type * as e from 'express'; import type * as e from 'express';
import type { Knex } from 'knex'; import type { Knex } from 'knex';
import {UserType} from "nocodb-sdk";
import {User} from "~/models";
export interface Route { export interface Route {
path: string; path: string;
@ -323,8 +325,9 @@ export interface AppConfig {
export interface NcRequest { export interface NcRequest {
id?: ReqId; id?: ReqId;
user?: Record<string, any>; user?: UserType | User;
ncWorkspaceId?: string; ncWorkspaceId?: string;
ncProjectId?: string; ncProjectId?: string;
headers?: Record<string, string | undefined> | IncomingHttpHeaders; headers?: Record<string, string | undefined> | IncomingHttpHeaders;
clientIp?: string;
} }

7
packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts

@ -35,6 +35,7 @@ import NcPluginMgrv2 from '~/helpers/NcPluginMgrv2';
import { BulkDataAliasService } from '~/services/bulk-data-alias.service'; import { BulkDataAliasService } from '~/services/bulk-data-alias.service';
import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2'; import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2';
import { sanitizeColumnName } from '~/helpers'; import { sanitizeColumnName } from '~/helpers';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class ImportService { export class ImportService {
@ -64,7 +65,7 @@ export class ImportService {
data: data:
| { models: { model: any; views: any[]; hooks?: any[] }[] } | { models: { model: any; views: any[]; hooks?: any[] }[] }
| { model: any; views: any[]; hooks?: any[] }[]; | { model: any; views: any[]; hooks?: any[] }[];
req: any; req: NcRequest;
externalModels?: Model[]; externalModels?: Model[];
}) { }) {
const hrTime = initTime(); const hrTime = initTime();
@ -1051,7 +1052,7 @@ export class ImportService {
vw: Partial<View>, vw: Partial<View>,
views: View[], views: View[],
user: UserType, user: UserType,
req: any, req: NcRequest,
): Promise<View> { ): Promise<View> {
if (vw.is_default) { if (vw.is_default) {
const view = views.find((a) => a.is_default); const view = views.find((a) => a.is_default);
@ -1197,7 +1198,7 @@ export class ImportService {
url?: string; url?: string;
file?: any; file?: any;
}; };
req: any; req: NcRequest;
}) { }) {
const hrTime = initTime(); const hrTime = initTime();

3
packages/nocodb/src/modules/jobs/jobs/meta-sync/meta-sync.processor.ts

@ -3,6 +3,7 @@ import { Process, Processor } from '@nestjs/bull';
import { Job } from 'bull'; import { Job } from 'bull';
import { JOBS_QUEUE, JobTypes } from '~/interface/Jobs'; import { JOBS_QUEUE, JobTypes } from '~/interface/Jobs';
import { MetaDiffsService } from '~/services/meta-diffs.service'; import { MetaDiffsService } from '~/services/meta-diffs.service';
import {NcRequest} from "~/interface/config";
@Processor(JOBS_QUEUE) @Processor(JOBS_QUEUE)
export class MetaSyncProcessor { export class MetaSyncProcessor {
@ -18,7 +19,7 @@ export class MetaSyncProcessor {
baseId: string; baseId: string;
sourceId: string; sourceId: string;
user: any; user: any;
req: any; req: NcRequest;
} = job.data; } = job.data;
if (info.sourceId === 'all') { if (info.sourceId === 'all') {

5
packages/nocodb/src/services/api-tokens.service.ts

@ -6,6 +6,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import { validatePayload } from '~/helpers'; import { validatePayload } from '~/helpers';
import { ApiToken } from '~/models'; import { ApiToken } from '~/models';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class ApiTokensService { export class ApiTokensService {
@ -17,7 +18,7 @@ export class ApiTokensService {
async apiTokenCreate(param: { async apiTokenCreate(param: {
userId: string; userId: string;
tokenBody: ApiTokenReqType; tokenBody: ApiTokenReqType;
req: any; req: NcRequest;
}) { }) {
validatePayload( validatePayload(
'swagger.json#/components/schemas/ApiTokenReq', 'swagger.json#/components/schemas/ApiTokenReq',
@ -36,7 +37,7 @@ export class ApiTokensService {
}); });
} }
async apiTokenDelete(param: { token; user: User; req: any }) { async apiTokenDelete(param: { token; user: User; req: NcRequest }) {
const apiToken = await ApiToken.getByToken(param.token); const apiToken = await ApiToken.getByToken(param.token);
if ( if (
!extractRolesObj(param.user.roles)[OrgUserRoles.SUPER_ADMIN] && !extractRolesObj(param.user.roles)[OrgUserRoles.SUPER_ADMIN] &&

2
packages/nocodb/src/services/app-hooks/interfaces.ts

@ -18,7 +18,7 @@ import type {
} from 'nocodb-sdk'; } from 'nocodb-sdk';
export interface NcBaseEvent extends NcBaseEvent { export interface NcBaseEvent extends NcBaseEvent {
req: any; req: NcRequest;
clientId?: string; clientId?: string;
} }

5
packages/nocodb/src/services/attachments.service.ts

@ -10,12 +10,13 @@ import Local from '~/plugins/storage/Local';
import mimetypes, { mimeIcons } from '~/utils/mimeTypes'; import mimetypes, { mimeIcons } from '~/utils/mimeTypes';
import { PresignedUrl } from '~/models'; import { PresignedUrl } from '~/models';
import { utf8ify } from '~/helpers/stringHelpers'; import { utf8ify } from '~/helpers/stringHelpers';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class AttachmentsService { export class AttachmentsService {
constructor(private readonly appHooksService: AppHooksService) {} constructor(private readonly appHooksService: AppHooksService) {}
async upload(param: { path?: string; files: FileType[]; req: any }) { async upload(param: { path?: string; files: FileType[]; req: NcRequest }) {
// TODO: add getAjvValidatorMw // TODO: add getAjvValidatorMw
const filePath = this.sanitizeUrlPath( const filePath = this.sanitizeUrlPath(
param.path?.toString()?.split('/') || [''], param.path?.toString()?.split('/') || [''],
@ -92,7 +93,7 @@ export class AttachmentsService {
async uploadViaURL(param: { async uploadViaURL(param: {
path?: string; path?: string;
urls: AttachmentReqType[]; urls: AttachmentReqType[];
req: any; req: NcRequest;
}) { }) {
// TODO: add getAjvValidatorMw // TODO: add getAjvValidatorMw
const filePath = this.sanitizeUrlPath( const filePath = this.sanitizeUrlPath(

3
packages/nocodb/src/services/base-users/base-users.service.ts

@ -23,6 +23,7 @@ import { Base, BaseUser, User } from '~/models';
import { CacheGetType, CacheScope, MetaTable } from '~/utils/globals'; import { CacheGetType, CacheScope, MetaTable } from '~/utils/globals';
import { extractProps } from '~/helpers/extractProps'; import { extractProps } from '~/helpers/extractProps';
import { getProjectRolePower } from '~/utils/roleHelper'; import { getProjectRolePower } from '~/utils/roleHelper';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class BaseUsersService { export class BaseUsersService {
@ -47,7 +48,7 @@ export class BaseUsersService {
async userInvite(param: { async userInvite(param: {
baseId: string; baseId: string;
baseUser: ProjectUserReqType; baseUser: ProjectUserReqType;
req: any; req: NcRequest;
}): Promise<any> { }): Promise<any> {
validatePayload( validatePayload(
'swagger.json#/components/schemas/ProjectUserReq', 'swagger.json#/components/schemas/ProjectUserReq',

11
packages/nocodb/src/services/bases.service.ts

@ -24,6 +24,7 @@ import { getToolDir } from '~/utils/nc-config';
import { MetaService } from '~/meta/meta.service'; import { MetaService } from '~/meta/meta.service';
import { MetaTable } from '~/utils/globals'; import { MetaTable } from '~/utils/globals';
import { TablesService } from '~/services/tables.service'; import { TablesService } from '~/services/tables.service';
import {NcRequest} from "~/interface/config";
const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 4); const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 4);
@ -36,7 +37,7 @@ export class BasesService {
) {} ) {}
async baseList(param: { async baseList(param: {
user: { id: string; roles: Record<string, boolean> }; user: { id: string; roles?: string | Record<string, boolean>};
query?: any; query?: any;
}) { }) {
const bases = extractRolesObj(param.user?.roles)[OrgUserRoles.SUPER_ADMIN] const bases = extractRolesObj(param.user?.roles)[OrgUserRoles.SUPER_ADMIN]
@ -63,7 +64,7 @@ export class BasesService {
baseId: string; baseId: string;
base: ProjectUpdateReqType; base: ProjectUpdateReqType;
user: UserType; user: UserType;
req: any; req: NcRequest;
}) { }) {
validatePayload( validatePayload(
'swagger.json#/components/schemas/ProjectUpdateReq', 'swagger.json#/components/schemas/ProjectUpdateReq',
@ -101,7 +102,7 @@ export class BasesService {
} }
} }
async baseSoftDelete(param: { baseId: any; user: UserType; req: any }) { async baseSoftDelete(param: { baseId: any; user: UserType; req: NcRequest }) {
const base = await Base.getWithInfo(param.baseId); const base = await Base.getWithInfo(param.baseId);
if (!base) { if (!base) {
@ -119,7 +120,7 @@ export class BasesService {
return true; return true;
} }
async baseCreate(param: { base: ProjectReqType; user: any; req: any }) { async baseCreate(param: { base: ProjectReqType; user: any; req: NcRequest }) {
validatePayload('swagger.json#/components/schemas/ProjectReq', param.base); validatePayload('swagger.json#/components/schemas/ProjectReq', param.base);
const baseId = await this.metaService.genNanoid(MetaTable.PROJECT); const baseId = await this.metaService.genNanoid(MetaTable.PROJECT);
@ -225,7 +226,7 @@ export class BasesService {
return base; return base;
} }
async createDefaultBase(param: { user: UserType; req: any }) { async createDefaultBase(param: { user: UserType; req: NcRequest }) {
const base = await this.baseCreate({ const base = await this.baseCreate({
base: { base: {
title: 'Getting Started', title: 'Getting Started',

5
packages/nocodb/src/services/columns.service.ts

@ -47,6 +47,7 @@ import Noco from '~/Noco';
import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2'; import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2';
import { MetaTable } from '~/utils/globals'; import { MetaTable } from '~/utils/globals';
import { MetaService } from '~/meta/meta.service'; import { MetaService } from '~/meta/meta.service';
import {NcRequest} from "~/interface/config";
// todo: move // todo: move
export enum Altered { export enum Altered {
@ -1030,7 +1031,7 @@ export class ColumnsService {
} }
async columnAdd(param: { async columnAdd(param: {
req: any; req: NcRequest;
tableId: string; tableId: string;
column: ColumnReqType; column: ColumnReqType;
user: UserType; user: UserType;
@ -2194,7 +2195,7 @@ export class ColumnsService {
column: Partial<Column>; column: Partial<Column>;
}[]; }[];
}, },
req: any, req: NcRequest,
) { ) {
// TODO validatePayload // TODO validatePayload

9
packages/nocodb/src/services/filters.service.ts

@ -5,6 +5,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { validatePayload } from '~/helpers'; import { validatePayload } from '~/helpers';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import { Filter, Hook, View } from '~/models'; import { Filter, Hook, View } from '~/models';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class FiltersService { export class FiltersService {
@ -14,7 +15,7 @@ export class FiltersService {
filter: FilterReqType; filter: FilterReqType;
hookId: any; hookId: any;
user: UserType; user: UserType;
req: any; req: NcRequest;
}) { }) {
validatePayload('swagger.json#/components/schemas/FilterReq', param.filter); validatePayload('swagger.json#/components/schemas/FilterReq', param.filter);
@ -41,7 +42,7 @@ export class FiltersService {
return Filter.rootFilterListByHook({ hookId: param.hookId }); return Filter.rootFilterListByHook({ hookId: param.hookId });
} }
async filterDelete(param: { filterId: string; req: any }) { async filterDelete(param: { filterId: string; req: NcRequest }) {
const filter = await Filter.get(param.filterId); const filter = await Filter.get(param.filterId);
if (!filter) { if (!filter) {
@ -62,7 +63,7 @@ export class FiltersService {
filter: FilterReqType; filter: FilterReqType;
viewId: string; viewId: string;
user: UserType; user: UserType;
req: any; req: NcRequest;
}) { }) {
validatePayload('swagger.json#/components/schemas/FilterReq', param.filter); validatePayload('swagger.json#/components/schemas/FilterReq', param.filter);
@ -86,7 +87,7 @@ export class FiltersService {
filter: FilterReqType; filter: FilterReqType;
filterId: string; filterId: string;
user: UserType; user: UserType;
req: any; req: NcRequest;
}) { }) {
validatePayload('swagger.json#/components/schemas/FilterReq', param.filter); validatePayload('swagger.json#/components/schemas/FilterReq', param.filter);

3
packages/nocodb/src/services/form-columns.service.ts

@ -3,6 +3,7 @@ import { AppEvents } from 'nocodb-sdk';
import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { validatePayload } from '~/helpers'; import { validatePayload } from '~/helpers';
import { FormViewColumn } from '~/models'; import { FormViewColumn } from '~/models';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class FormColumnsService { export class FormColumnsService {
@ -12,7 +13,7 @@ export class FormColumnsService {
formViewColumnId: string; formViewColumnId: string;
// todo: replace with FormColumnReq // todo: replace with FormColumnReq
formViewColumn: FormViewColumn; formViewColumn: FormViewColumn;
req: any; req: NcRequest;
}) { }) {
validatePayload( validatePayload(
'swagger.json#/components/schemas/FormColumnReq', 'swagger.json#/components/schemas/FormColumnReq',

5
packages/nocodb/src/services/forms.service.ts

@ -9,6 +9,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { validatePayload } from '~/helpers'; import { validatePayload } from '~/helpers';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import { FormView, View } from '~/models'; import { FormView, View } from '~/models';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class FormsService { export class FormsService {
@ -23,7 +24,7 @@ export class FormsService {
tableId: string; tableId: string;
body: ViewCreateReqType; body: ViewCreateReqType;
user: UserType; user: UserType;
req: any; req: NcRequest;
}) { }) {
validatePayload( validatePayload(
'swagger.json#/components/schemas/ViewCreateReq', 'swagger.json#/components/schemas/ViewCreateReq',
@ -55,7 +56,7 @@ export class FormsService {
async formViewUpdate(param: { async formViewUpdate(param: {
formViewId: string; formViewId: string;
form: FormUpdateReqType; form: FormUpdateReqType;
req: any; req: NcRequest;
}) { }) {
validatePayload( validatePayload(
'swagger.json#/components/schemas/FormUpdateReq', 'swagger.json#/components/schemas/FormUpdateReq',

5
packages/nocodb/src/services/galleries.service.ts

@ -9,6 +9,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { validatePayload } from '~/helpers'; import { validatePayload } from '~/helpers';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import { GalleryView, View } from '~/models'; import { GalleryView, View } from '~/models';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class GalleriesService { export class GalleriesService {
@ -23,7 +24,7 @@ export class GalleriesService {
gallery: ViewCreateReqType; gallery: ViewCreateReqType;
user: UserType; user: UserType;
req: any; req: NcRequest;
}) { }) {
validatePayload( validatePayload(
'swagger.json#/components/schemas/ViewCreateReq', 'swagger.json#/components/schemas/ViewCreateReq',
@ -48,7 +49,7 @@ export class GalleriesService {
async galleryViewUpdate(param: { async galleryViewUpdate(param: {
galleryViewId: string; galleryViewId: string;
gallery: GalleryUpdateReqType; gallery: GalleryUpdateReqType;
req: any; req: NcRequest;
}) { }) {
validatePayload( validatePayload(
'swagger.json#/components/schemas/GalleryUpdateReq', 'swagger.json#/components/schemas/GalleryUpdateReq',

3
packages/nocodb/src/services/grid-columns.service.ts

@ -4,6 +4,7 @@ import type { GridColumnReqType } from 'nocodb-sdk';
import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { validatePayload } from '~/helpers'; import { validatePayload } from '~/helpers';
import { GridViewColumn } from '~/models'; import { GridViewColumn } from '~/models';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class GridColumnsService { export class GridColumnsService {
@ -16,7 +17,7 @@ export class GridColumnsService {
async gridColumnUpdate(param: { async gridColumnUpdate(param: {
gridViewColumnId: string; gridViewColumnId: string;
grid: GridColumnReqType; grid: GridColumnReqType;
req: any; req: NcRequest;
}) { }) {
validatePayload( validatePayload(
'swagger.json#/components/schemas/GridColumnReq', 'swagger.json#/components/schemas/GridColumnReq',

5
packages/nocodb/src/services/grids.service.ts

@ -5,6 +5,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { validatePayload } from '~/helpers'; import { validatePayload } from '~/helpers';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import { GridView, View } from '~/models'; import { GridView, View } from '~/models';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class GridsService { export class GridsService {
@ -13,7 +14,7 @@ export class GridsService {
async gridViewCreate(param: { async gridViewCreate(param: {
tableId: string; tableId: string;
grid: ViewCreateReqType; grid: ViewCreateReqType;
req: any; req: NcRequest;
}) { }) {
validatePayload( validatePayload(
'swagger.json#/components/schemas/ViewCreateReq', 'swagger.json#/components/schemas/ViewCreateReq',
@ -39,7 +40,7 @@ export class GridsService {
async gridViewUpdate(param: { async gridViewUpdate(param: {
viewId: string; viewId: string;
grid: GridUpdateReqType; grid: GridUpdateReqType;
req: any; req: NcRequest;
}) { }) {
validatePayload( validatePayload(
'swagger.json#/components/schemas/GridUpdateReq', 'swagger.json#/components/schemas/GridUpdateReq',

9
packages/nocodb/src/services/hooks.service.ts

@ -10,6 +10,7 @@ import {
} from '~/helpers/populateSamplePayload'; } from '~/helpers/populateSamplePayload';
import { invokeWebhook } from '~/helpers/webhookHelpers'; import { invokeWebhook } from '~/helpers/webhookHelpers';
import { Hook, HookLog, Model } from '~/models'; import { Hook, HookLog, Model } from '~/models';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class HooksService { export class HooksService {
@ -37,7 +38,7 @@ export class HooksService {
return await HookLog.list({ fk_hook_id: param.hookId }, param.query); return await HookLog.list({ fk_hook_id: param.hookId }, param.query);
} }
async hookCreate(param: { tableId: string; hook: HookReqType; req: any }) { async hookCreate(param: { tableId: string; hook: HookReqType; req: NcRequest }) {
validatePayload('swagger.json#/components/schemas/HookReq', param.hook); validatePayload('swagger.json#/components/schemas/HookReq', param.hook);
this.validateHookPayload(param.hook.notification); this.validateHookPayload(param.hook.notification);
@ -55,7 +56,7 @@ export class HooksService {
return hook; return hook;
} }
async hookDelete(param: { hookId: string; req: any }) { async hookDelete(param: { hookId: string; req: NcRequest }) {
const hook = await Hook.get(param.hookId); const hook = await Hook.get(param.hookId);
if (!hook) { if (!hook) {
@ -70,7 +71,7 @@ export class HooksService {
return true; return true;
} }
async hookUpdate(param: { hookId: string; hook: HookReqType; req: any }) { async hookUpdate(param: { hookId: string; hook: HookReqType; req: NcRequest }) {
validatePayload('swagger.json#/components/schemas/HookReq', param.hook); validatePayload('swagger.json#/components/schemas/HookReq', param.hook);
const hook = await Hook.get(param.hookId); const hook = await Hook.get(param.hookId);
@ -97,7 +98,7 @@ export class HooksService {
async hookTest(param: { async hookTest(param: {
tableId: string; tableId: string;
hookTest: HookTestReqType; hookTest: HookTestReqType;
req: any; req: NcRequest;
}) { }) {
validatePayload( validatePayload(
'swagger.json#/components/schemas/HookTestReq', 'swagger.json#/components/schemas/HookTestReq',

5
packages/nocodb/src/services/kanbans.service.ts

@ -9,6 +9,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { validatePayload } from '~/helpers'; import { validatePayload } from '~/helpers';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import { KanbanView, View } from '~/models'; import { KanbanView, View } from '~/models';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class KanbansService { export class KanbansService {
@ -22,7 +23,7 @@ export class KanbansService {
tableId: string; tableId: string;
kanban: ViewCreateReqType; kanban: ViewCreateReqType;
user: UserType; user: UserType;
req: any; req: NcRequest;
}) { }) {
validatePayload( validatePayload(
'swagger.json#/components/schemas/ViewCreateReq', 'swagger.json#/components/schemas/ViewCreateReq',
@ -50,7 +51,7 @@ export class KanbansService {
async kanbanViewUpdate(param: { async kanbanViewUpdate(param: {
kanbanViewId: string; kanbanViewId: string;
kanban: KanbanUpdateReqType; kanban: KanbanUpdateReqType;
req: any; req: NcRequest;
}) { }) {
validatePayload( validatePayload(
'swagger.json#/components/schemas/KanbanUpdateReq', 'swagger.json#/components/schemas/KanbanUpdateReq',

5
packages/nocodb/src/services/maps.service.ts

@ -5,6 +5,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { validatePayload } from '~/helpers'; import { validatePayload } from '~/helpers';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import { MapView, View } from '~/models'; import { MapView, View } from '~/models';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class MapsService { export class MapsService {
@ -18,7 +19,7 @@ export class MapsService {
tableId: string; tableId: string;
map: ViewCreateReqType; map: ViewCreateReqType;
user: UserType; user: UserType;
req: any; req: NcRequest;
}) { }) {
validatePayload( validatePayload(
'swagger.json#/components/schemas/ViewCreateReq', 'swagger.json#/components/schemas/ViewCreateReq',
@ -44,7 +45,7 @@ export class MapsService {
async mapViewUpdate(param: { async mapViewUpdate(param: {
mapViewId: string; mapViewId: string;
map: MapUpdateReqType; map: MapUpdateReqType;
req: any; req: NcRequest;
}) { }) {
validatePayload('swagger.json#/components/schemas/MapUpdateReq', param.map); validatePayload('swagger.json#/components/schemas/MapUpdateReq', param.map);

3
packages/nocodb/src/services/model-visibilities.service.ts

@ -5,6 +5,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { validatePayload } from '~/helpers'; import { validatePayload } from '~/helpers';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import { Base, Model, ModelRoleVisibility, View } from '~/models'; import { Base, Model, ModelRoleVisibility, View } from '~/models';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class ModelVisibilitiesService { export class ModelVisibilitiesService {
@ -13,7 +14,7 @@ export class ModelVisibilitiesService {
async xcVisibilityMetaSetAll(param: { async xcVisibilityMetaSetAll(param: {
visibilityRule: VisibilityRuleReqType; visibilityRule: VisibilityRuleReqType;
baseId: string; baseId: string;
req: any; req: NcRequest;
}) { }) {
validatePayload( validatePayload(
'swagger.json#/components/schemas/VisibilityRuleReq', 'swagger.json#/components/schemas/VisibilityRuleReq',

3
packages/nocodb/src/services/notifications.service.ts

@ -10,6 +10,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import { PagedResponseImpl } from '~/helpers/PagedResponse'; import { PagedResponseImpl } from '~/helpers/PagedResponse';
import { Notification } from '~/models'; import { Notification } from '~/models';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class NotificationsService implements OnModuleInit, OnModuleDestroy { export class NotificationsService implements OnModuleInit, OnModuleDestroy {
@ -17,7 +18,7 @@ export class NotificationsService implements OnModuleInit, OnModuleDestroy {
protected async insertNotification( protected async insertNotification(
insertData: Partial<Notification>, insertData: Partial<Notification>,
req: any, req: NcRequest,
) { ) {
this.appHooks.emit('notification' as any, { ...insertData, req } as any); this.appHooks.emit('notification' as any, { ...insertData, req } as any);

5
packages/nocodb/src/services/org-tokens.service.ts

@ -7,6 +7,7 @@ import { validatePayload } from '~/helpers';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import { PagedResponseImpl } from '~/helpers/PagedResponse'; import { PagedResponseImpl } from '~/helpers/PagedResponse';
import { ApiToken } from '~/models'; import { ApiToken } from '~/models';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class OrgTokensService { export class OrgTokensService {
@ -38,7 +39,7 @@ export class OrgTokensService {
async apiTokenCreate(param: { async apiTokenCreate(param: {
user: User; user: User;
apiToken: ApiTokenReqType; apiToken: ApiTokenReqType;
req: any; req: NcRequest;
}) { }) {
validatePayload( validatePayload(
'swagger.json#/components/schemas/ApiTokenReq', 'swagger.json#/components/schemas/ApiTokenReq',
@ -60,7 +61,7 @@ export class OrgTokensService {
return apiToken; return apiToken;
} }
async apiTokenDelete(param: { user: User; token: string; req: any }) { async apiTokenDelete(param: { user: User; token: string; req: NcRequest }) {
const fk_user_id = param.user.id; const fk_user_id = param.user.id;
const apiToken = await ApiToken.getByToken(param.token); const apiToken = await ApiToken.getByToken(param.token);
if ( if (

5
packages/nocodb/src/services/org-users.service.ts

@ -19,6 +19,7 @@ import { BaseUser, Store, SyncSource, User } from '~/models';
import Noco from '~/Noco'; import Noco from '~/Noco';
import { MetaTable } from '~/utils/globals'; import { MetaTable } from '~/utils/globals';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class OrgUsersService { export class OrgUsersService {
@ -91,7 +92,7 @@ export class OrgUsersService {
async userAdd(param: { async userAdd(param: {
user: UserType; user: UserType;
// todo: refactor // todo: refactor
req: any; req: NcRequest;
}) { }) {
validatePayload('swagger.json#/components/schemas/OrgUserReq', param.user); validatePayload('swagger.json#/components/schemas/OrgUserReq', param.user);
@ -193,7 +194,7 @@ export class OrgUsersService {
NcError.notImplemented(); NcError.notImplemented();
} }
async userInviteResend(param: { userId: string; req: any }): Promise<any> { async userInviteResend(param: { userId: string; req: NcRequest }): Promise<any> {
const user = await User.get(param.userId); const user = await User.get(param.userId);
if (!user) { if (!user) {

5
packages/nocodb/src/services/plugins.service.ts

@ -5,6 +5,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { validatePayload } from '~/helpers'; import { validatePayload } from '~/helpers';
import NcPluginMgrv2 from '~/helpers/NcPluginMgrv2'; import NcPluginMgrv2 from '~/helpers/NcPluginMgrv2';
import { Plugin } from '~/models'; import { Plugin } from '~/models';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class PluginsService { export class PluginsService {
@ -14,7 +15,7 @@ export class PluginsService {
return await Plugin.list(); return await Plugin.list();
} }
async pluginTest(param: { body: PluginTestReqType; req: any }) { async pluginTest(param: { body: PluginTestReqType; req: NcRequest }) {
validatePayload( validatePayload(
'swagger.json#/components/schemas/PluginTestReq', 'swagger.json#/components/schemas/PluginTestReq',
param.body, param.body,
@ -33,7 +34,7 @@ export class PluginsService {
async pluginUpdate(param: { async pluginUpdate(param: {
pluginId: string; pluginId: string;
plugin: PluginType; plugin: PluginType;
req: any; req: NcRequest;
}) { }) {
validatePayload('swagger.json#/components/schemas/PluginReq', param.plugin); validatePayload('swagger.json#/components/schemas/PluginReq', param.plugin);

8
packages/nocodb/src/services/shared-bases.service.ts

@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common';
import { AppEvents } from 'nocodb-sdk'; import { AppEvents } from 'nocodb-sdk';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import { ConfigService } from '@nestjs/config'; import { ConfigService } from '@nestjs/config';
import type { AppConfig } from '~/interface/config'; import type {AppConfig, NcRequest} from '~/interface/config';
import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { validatePayload } from '~/helpers'; import { validatePayload } from '~/helpers';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
@ -26,7 +26,7 @@ export class SharedBasesService {
password: string; password: string;
siteUrl: string; siteUrl: string;
req: any; req: NcRequest;
}): Promise<any> { }): Promise<any> {
validatePayload('swagger.json#/components/schemas/SharedBaseReq', param); validatePayload('swagger.json#/components/schemas/SharedBaseReq', param);
@ -74,7 +74,7 @@ export class SharedBasesService {
roles: string; roles: string;
password: string; password: string;
siteUrl: string; siteUrl: string;
req: any; req: NcRequest;
}): Promise<any> { }): Promise<any> {
validatePayload('swagger.json#/components/schemas/SharedBaseReq', param); validatePayload('swagger.json#/components/schemas/SharedBaseReq', param);
@ -132,7 +132,7 @@ export class SharedBasesService {
async disableSharedBaseLink(param: { async disableSharedBaseLink(param: {
baseId: string; baseId: string;
req: any; req: NcRequest;
}): Promise<any> { }): Promise<any> {
const base = await Base.get(param.baseId); const base = await Base.get(param.baseId);

7
packages/nocodb/src/services/sorts.service.ts

@ -5,6 +5,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { validatePayload } from '~/helpers'; import { validatePayload } from '~/helpers';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import { Sort } from '~/models'; import { Sort } from '~/models';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class SortsService { export class SortsService {
@ -14,7 +15,7 @@ export class SortsService {
return Sort.get(param.sortId); return Sort.get(param.sortId);
} }
async sortDelete(param: { sortId: string; req: any }) { async sortDelete(param: { sortId: string; req: NcRequest }) {
const sort = await Sort.get(param.sortId); const sort = await Sort.get(param.sortId);
if (!sort) { if (!sort) {
@ -30,7 +31,7 @@ export class SortsService {
return true; return true;
} }
async sortUpdate(param: { sortId: any; sort: SortReqType; req: any }) { async sortUpdate(param: { sortId: any; sort: SortReqType; req: NcRequest }) {
validatePayload('swagger.json#/components/schemas/SortReq', param.sort); validatePayload('swagger.json#/components/schemas/SortReq', param.sort);
const sort = await Sort.get(param.sortId); const sort = await Sort.get(param.sortId);
@ -50,7 +51,7 @@ export class SortsService {
return res; return res;
} }
async sortCreate(param: { viewId: any; sort: SortReqType; req: any }) { async sortCreate(param: { viewId: any; sort: SortReqType; req: NcRequest }) {
validatePayload('swagger.json#/components/schemas/SortReq', param.sort); validatePayload('swagger.json#/components/schemas/SortReq', param.sort);
const sort = await Sort.insert({ const sort = await Sort.insert({

7
packages/nocodb/src/services/sources.service.ts

@ -7,6 +7,7 @@ import { populateRollupColumnAndHideLTAR } from '~/helpers/populateMeta';
import { syncBaseMigration } from '~/helpers/syncMigration'; import { syncBaseMigration } from '~/helpers/syncMigration';
import { Base, Source } from '~/models'; import { Base, Source } from '~/models';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class SourcesService { export class SourcesService {
@ -24,7 +25,7 @@ export class SourcesService {
sourceId: string; sourceId: string;
source: BaseReqType; source: BaseReqType;
baseId: string; baseId: string;
req: any; req: NcRequest;
}) { }) {
validatePayload('swagger.json#/components/schemas/BaseReq', param.source); validatePayload('swagger.json#/components/schemas/BaseReq', param.source);
@ -53,7 +54,7 @@ export class SourcesService {
return sources; return sources;
} }
async baseDelete(param: { sourceId: string; req: any }) { async baseDelete(param: { sourceId: string; req: NcRequest }) {
try { try {
const source = await Source.get(param.sourceId, true); const source = await Source.get(param.sourceId, true);
await source.delete(); await source.delete();
@ -81,7 +82,7 @@ export class SourcesService {
baseId: string; baseId: string;
source: BaseReqType; source: BaseReqType;
logger?: (message: string) => void; logger?: (message: string) => void;
req: any; req: NcRequest;
}) { }) {
validatePayload('swagger.json#/components/schemas/BaseReq', param.source); validatePayload('swagger.json#/components/schemas/BaseReq', param.source);

7
packages/nocodb/src/services/sync.service.ts

@ -4,6 +4,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import { PagedResponseImpl } from '~/helpers/PagedResponse'; import { PagedResponseImpl } from '~/helpers/PagedResponse';
import { Base, SyncSource } from '~/models'; import { Base, SyncSource } from '~/models';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class SyncService { export class SyncService {
@ -20,7 +21,7 @@ export class SyncService {
sourceId?: string; sourceId?: string;
userId: string; userId: string;
syncPayload: Partial<SyncSource>; syncPayload: Partial<SyncSource>;
req: any; req: NcRequest;
}) { }) {
const base = await Base.getWithInfo(param.baseId); const base = await Base.getWithInfo(param.baseId);
@ -39,7 +40,7 @@ export class SyncService {
return sync; return sync;
} }
async syncDelete(param: { syncId: string; req: any }) { async syncDelete(param: { syncId: string; req: NcRequest }) {
const syncSource = await SyncSource.get(param.syncId); const syncSource = await SyncSource.get(param.syncId);
if (!syncSource) { if (!syncSource) {
@ -58,7 +59,7 @@ export class SyncService {
async syncUpdate(param: { async syncUpdate(param: {
syncId: string; syncId: string;
syncPayload: Partial<SyncSource>; syncPayload: Partial<SyncSource>;
req: any; req: NcRequest;
}) { }) {
const syncSource = await SyncSource.get(param.syncId); const syncSource = await SyncSource.get(param.syncId);

3
packages/nocodb/src/services/tables.service.ts

@ -29,6 +29,7 @@ import { Base, Column, Model, ModelRoleVisibility } from '~/models';
import Noco from '~/Noco'; import Noco from '~/Noco';
import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2'; import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2';
import { sanitizeColumnName, validatePayload } from '~/helpers'; import { sanitizeColumnName, validatePayload } from '~/helpers';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class TablesService { export class TablesService {
@ -43,7 +44,7 @@ export class TablesService {
table: TableReqType & { base_id?: string }; table: TableReqType & { base_id?: string };
baseId?: string; baseId?: string;
user: UserType; user: UserType;
req: any; req: NcRequest;
}) { }) {
const model = await Model.get(param.tableId); const model = await Model.get(param.tableId);

11
packages/nocodb/src/services/users/users.service.ts

@ -26,6 +26,7 @@ import NcPluginMgrv2 from '~/helpers/NcPluginMgrv2';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import { BasesService } from '~/services/bases.service'; import { BasesService } from '~/services/bases.service';
import { extractProps } from '~/helpers/extractProps'; import { extractProps } from '~/helpers/extractProps';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class UsersService { export class UsersService {
@ -97,7 +98,7 @@ export class UsersService {
salt: any; salt: any;
password; password;
email_verification_token; email_verification_token;
req: any; req: NcRequest;
}) { }) {
this.validateEmailPattern(email); this.validateEmailPattern(email);
@ -149,7 +150,7 @@ export class UsersService {
async passwordChange(param: { async passwordChange(param: {
body: PasswordChangeReqType; body: PasswordChangeReqType;
user: UserType; user: UserType;
req: any; req: NcRequest;
}): Promise<any> { }): Promise<any> {
validatePayload( validatePayload(
'swagger.json#/components/schemas/PasswordChangeReq', 'swagger.json#/components/schemas/PasswordChangeReq',
@ -202,7 +203,7 @@ export class UsersService {
async passwordForgot(param: { async passwordForgot(param: {
body: PasswordForgotReqType; body: PasswordForgotReqType;
siteUrl: string; siteUrl: string;
req: any; req: NcRequest;
}): Promise<any> { }): Promise<any> {
validatePayload( validatePayload(
'swagger.json#/components/schemas/PasswordForgotReq', 'swagger.json#/components/schemas/PasswordForgotReq',
@ -279,7 +280,7 @@ export class UsersService {
async passwordReset(param: { async passwordReset(param: {
body: PasswordResetReqType; body: PasswordResetReqType;
token: string; token: string;
req: any; req: NcRequest;
}): Promise<any> { }): Promise<any> {
validatePayload( validatePayload(
'swagger.json#/components/schemas/PasswordResetReq', 'swagger.json#/components/schemas/PasswordResetReq',
@ -332,7 +333,7 @@ export class UsersService {
async emailVerification(param: { async emailVerification(param: {
token: string; token: string;
// todo: exclude // todo: exclude
req: any; req: NcRequest;
}): Promise<any> { }): Promise<any> {
const { token, req } = param; const { token, req } = param;

5
packages/nocodb/src/services/view-columns.service.ts

@ -4,6 +4,7 @@ import type { ViewColumnReqType, ViewColumnUpdateReqType } from 'nocodb-sdk';
import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { validatePayload } from '~/helpers'; import { validatePayload } from '~/helpers';
import { View } from '~/models'; import { View } from '~/models';
import {NcRequest} from "~/interface/config";
@Injectable() @Injectable()
export class ViewColumnsService { export class ViewColumnsService {
@ -15,7 +16,7 @@ export class ViewColumnsService {
async columnAdd(param: { async columnAdd(param: {
viewId: string; viewId: string;
column: ViewColumnReqType; column: ViewColumnReqType;
req: any; req: NcRequest;
}) { }) {
validatePayload( validatePayload(
'swagger.json#/components/schemas/ViewColumnReq', 'swagger.json#/components/schemas/ViewColumnReq',
@ -42,7 +43,7 @@ export class ViewColumnsService {
viewId: string; viewId: string;
columnId: string; columnId: string;
column: ViewColumnUpdateReqType; column: ViewColumnUpdateReqType;
req: any; req: NcRequest;
}) { }) {
validatePayload( validatePayload(
'swagger.json#/components/schemas/ViewColumnUpdateReq', 'swagger.json#/components/schemas/ViewColumnUpdateReq',

15
packages/nocodb/src/services/views.service.ts

@ -9,6 +9,7 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { validatePayload } from '~/helpers'; import { validatePayload } from '~/helpers';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import { Model, ModelRoleVisibility, View } from '~/models'; import { Model, ModelRoleVisibility, View } from '~/models';
import {NcRequest} from "~/interface/config";
// todo: move // todo: move
async function xcVisibilityMetaGet(param: { async function xcVisibilityMetaGet(param: {
@ -69,8 +70,8 @@ export class ViewsService {
async viewList(param: { async viewList(param: {
tableId: string; tableId: string;
user: { user: {
roles: Record<string, boolean>; roles?: Record<string, boolean> | string,
base_roles: Record<string, boolean>; base_roles?: Record<string, boolean>;
}; };
}) { }) {
const model = await Model.get(param.tableId); const model = await Model.get(param.tableId);
@ -91,7 +92,7 @@ export class ViewsService {
return filteredViewList; return filteredViewList;
} }
async shareView(param: { viewId: string; user: UserType; req: any }) { async shareView(param: { viewId: string; user: UserType; req: NcRequest }) {
const res = await View.share(param.viewId); const res = await View.share(param.viewId);
const view = await View.get(param.viewId); const view = await View.get(param.viewId);
@ -113,7 +114,7 @@ export class ViewsService {
viewId: string; viewId: string;
view: ViewUpdateReqType; view: ViewUpdateReqType;
user: UserType; user: UserType;
req: any; req: NcRequest;
}) { }) {
validatePayload( validatePayload(
'swagger.json#/components/schemas/ViewUpdateReq', 'swagger.json#/components/schemas/ViewUpdateReq',
@ -140,7 +141,7 @@ export class ViewsService {
return result; return result;
} }
async viewDelete(param: { viewId: string; user: UserType; req: any }) { async viewDelete(param: { viewId: string; user: UserType; req: NcRequest }) {
const view = await View.get(param.viewId); const view = await View.get(param.viewId);
if (!view) { if (!view) {
@ -162,7 +163,7 @@ export class ViewsService {
viewId: string; viewId: string;
sharedView: SharedViewReqType; sharedView: SharedViewReqType;
user: UserType; user: UserType;
req: any; req: NcRequest;
}) { }) {
validatePayload( validatePayload(
'swagger.json#/components/schemas/SharedViewReq', 'swagger.json#/components/schemas/SharedViewReq',
@ -186,7 +187,7 @@ export class ViewsService {
return result; return result;
} }
async shareViewDelete(param: { viewId: string; user: UserType; req: any }) { async shareViewDelete(param: { viewId: string; user: UserType; req: NcRequest }) {
const view = await View.get(param.viewId); const view = await View.get(param.viewId);
if (!view) { if (!view) {

3
packages/nocodb/src/strategies/authtoken.strategy/authtoken.strategy.ts

@ -4,11 +4,12 @@ import { extractRolesObj, ProjectRoles } from 'nocodb-sdk';
import { Strategy } from 'passport-custom'; import { Strategy } from 'passport-custom';
import { ApiToken, BaseUser, User } from '~/models'; import { ApiToken, BaseUser, User } from '~/models';
import { sanitiseUserObj } from '~/utils'; import { sanitiseUserObj } from '~/utils';
import {Request} from 'express'
@Injectable() @Injectable()
export class AuthTokenStrategy extends PassportStrategy(Strategy, 'authtoken') { export class AuthTokenStrategy extends PassportStrategy(Strategy, 'authtoken') {
// eslint-disable-next-line @typescript-eslint/ban-types // eslint-disable-next-line @typescript-eslint/ban-types
async validate(req: any, callback: Function) { async validate(req: Request, callback: Function) {
try { try {
let user; let user;
if (req.headers['xc-token']) { if (req.headers['xc-token']) {

4
packages/nocodb/src/strategies/base-view.strategy/base-view.strategy.ts

@ -3,11 +3,13 @@ import { PassportStrategy } from '@nestjs/passport';
import { Strategy } from 'passport-custom'; import { Strategy } from 'passport-custom';
import { extractRolesObj } from 'nocodb-sdk'; import { extractRolesObj } from 'nocodb-sdk';
import { Base } from '~/models'; import { Base } from '~/models';
import {Request} from 'express'
@Injectable() @Injectable()
export class BaseViewStrategy extends PassportStrategy(Strategy, 'base-view') { export class BaseViewStrategy extends PassportStrategy(Strategy, 'base-view') {
// eslint-disable-next-line @typescript-eslint/ban-types // eslint-disable-next-line @typescript-eslint/ban-types
async validate(req: any, callback: Function) { async validate(req: Request, callback: Function) {
try { try {
let user; let user;
if (req.headers['xc-shared-base-id']) { if (req.headers['xc-shared-base-id']) {

5
packages/nocodb/src/strategies/google.strategy/google.strategy.ts

@ -9,6 +9,7 @@ import Noco from '~/Noco';
import { UsersService } from '~/services/users/users.service'; import { UsersService } from '~/services/users/users.service';
import { BaseUser, Plugin, User } from '~/models'; import { BaseUser, Plugin, User } from '~/models';
import { sanitiseUserObj } from '~/utils'; import { sanitiseUserObj } from '~/utils';
import {Request} from 'express'
@Injectable() @Injectable()
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') { export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
@ -20,7 +21,7 @@ export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
} }
async validate( async validate(
req: any, req: Request,
accessToken: string, accessToken: string,
refreshToken: string, refreshToken: string,
profile: any, profile: any,
@ -72,7 +73,7 @@ export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
return params; return params;
} }
async authenticate(req: any, options?: any): Promise<void> { async authenticate(req: Request, options?: any): Promise<void> {
const googlePlugin = await Plugin.getPluginByTitle('Google'); const googlePlugin = await Plugin.getPluginByTitle('Google');
if (googlePlugin && googlePlugin.input) { if (googlePlugin && googlePlugin.input) {

8
packages/nocodb/src/types/express.d.ts vendored

@ -1,5 +1,7 @@
import * as express from 'express'; import * as express from 'express';
import { Express } from 'express-serve-static-core'; import { Express } from 'express-serve-static-core';
import type { UserType } from 'nocodb-sdk';
import { User } from '~/models';
// declare global { // declare global {
// namespace Express { // namespace Express {
@ -20,7 +22,11 @@ declare module 'express-serve-static-core' {
interface Request { interface Request {
ncWorkspaceId?: string; ncWorkspaceId?: string;
ncProjectId?: string; ncProjectId?: string;
user: any; user: UserType & {
base_roles?: Record<string, boolean>;
workspace_roles?: Record<string, boolean>;
provider?: string;
};
ncSiteUrl: string; ncSiteUrl: string;
clientIp: string; clientIp: string;
} }

Loading…
Cancel
Save