From 9320da8bf3af4db4a0777e810e94cd57108e5470 Mon Sep 17 00:00:00 2001 From: mertmit Date: Tue, 12 Dec 2023 17:03:05 +0300 Subject: [PATCH] fix: rename ncProjectId to ncBaseId Signed-off-by: mertmit --- .../src/controllers/tables.controller.ts | 4 +- .../global-exception.filter.ts | 2 +- packages/nocodb/src/interface/config.ts | 2 +- .../extract-ids/extract-ids.middleware.ts | 38 +++++++++---------- .../authtoken.strategy/authtoken.strategy.ts | 2 +- .../base-view.strategy/base-view.strategy.ts | 2 +- .../google.strategy/google.strategy.ts | 4 +- .../nocodb/src/strategies/jwt.strategy.ts | 2 +- packages/nocodb/src/types/express.d.ts | 2 +- 9 files changed, 29 insertions(+), 29 deletions(-) diff --git a/packages/nocodb/src/controllers/tables.controller.ts b/packages/nocodb/src/controllers/tables.controller.ts index e77b741aa9..9cd7f0c4fa 100644 --- a/packages/nocodb/src/controllers/tables.controller.ts +++ b/packages/nocodb/src/controllers/tables.controller.ts @@ -91,8 +91,8 @@ export class TablesController { await this.tablesService.tableUpdate({ tableId: tableId, table: body, - baseId: req.ncProjectId, - user: req.ncProjectId, + baseId: req.ncBaseId, + user: req.ncBaseId, req, }); return { msg: 'The table has been updated successfully' }; diff --git a/packages/nocodb/src/filters/global-exception/global-exception.filter.ts b/packages/nocodb/src/filters/global-exception/global-exception.filter.ts index bb191405dc..9a5806f9d7 100644 --- a/packages/nocodb/src/filters/global-exception/global-exception.filter.ts +++ b/packages/nocodb/src/filters/global-exception/global-exception.filter.ts @@ -49,7 +49,7 @@ export class GlobalExceptionFilter implements ExceptionFilter { this.logger.warn( `${exception.message}, Path : ${request.path}, Workspace ID : ${ (request as any).ncWorkspaceId - }, Project ID : ${(request as any).ncProjectId}`, + }, Project ID : ${(request as any).ncBaseId}`, ); } diff --git a/packages/nocodb/src/interface/config.ts b/packages/nocodb/src/interface/config.ts index 57498647a5..b6a984f6ea 100644 --- a/packages/nocodb/src/interface/config.ts +++ b/packages/nocodb/src/interface/config.ts @@ -327,7 +327,7 @@ export interface NcRequest { id?: ReqId; user?: UserType | User; ncWorkspaceId?: string; - ncProjectId?: string; + ncBaseId?: string; headers?: Record | IncomingHttpHeaders; clientIp?: string; } diff --git a/packages/nocodb/src/middlewares/extract-ids/extract-ids.middleware.ts b/packages/nocodb/src/middlewares/extract-ids/extract-ids.middleware.ts index d6df48c906..f9f2133336 100644 --- a/packages/nocodb/src/middlewares/extract-ids/extract-ids.middleware.ts +++ b/packages/nocodb/src/middlewares/extract-ids/extract-ids.middleware.ts @@ -60,23 +60,23 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate { if (params.baseName) { const base = await Base.getByTitleOrId(params.baseName); if (base) { - req.ncProjectId = base.id; + req.ncBaseId = base.id; res.locals.base = base; } } if (params.baseId) { - req.ncProjectId = params.baseId; + req.ncBaseId = params.baseId; } else if (params.dashboardId) { - req.ncProjectId = params.dashboardId; + req.ncBaseId = params.dashboardId; } else if (params.tableId || params.modelId) { const model = await Model.getByIdOrName({ id: params.tableId || params.modelId, }); - req.ncProjectId = model?.base_id; + req.ncBaseId = model?.base_id; } else if (params.viewId) { const view = (await View.get(params.viewId)) || (await Model.get(params.viewId)); - req.ncProjectId = view?.base_id; + req.ncBaseId = view?.base_id; } else if ( params.formViewId || params.gridViewId || @@ -89,39 +89,39 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate { params.kanbanViewId || params.galleryViewId, ); - req.ncProjectId = view?.base_id; + req.ncBaseId = view?.base_id; } else if (params.publicDataUuid) { const view = await View.getByUUID(req.params.publicDataUuid); - req.ncProjectId = view?.base_id; + req.ncBaseId = view?.base_id; } else if (params.hookId) { const hook = await Hook.get(params.hookId); - req.ncProjectId = hook?.base_id; + req.ncBaseId = hook?.base_id; } else if (params.gridViewColumnId) { const gridViewColumn = await GridViewColumn.get(params.gridViewColumnId); - req.ncProjectId = gridViewColumn?.base_id; + req.ncBaseId = gridViewColumn?.base_id; } else if (params.formViewColumnId) { const formViewColumn = await FormViewColumn.get(params.formViewColumnId); - req.ncProjectId = formViewColumn?.base_id; + req.ncBaseId = formViewColumn?.base_id; } else if (params.galleryViewColumnId) { const galleryViewColumn = await GalleryViewColumn.get( params.galleryViewColumnId, ); - req.ncProjectId = galleryViewColumn?.base_id; + req.ncBaseId = galleryViewColumn?.base_id; } else if (params.columnId) { const column = await Column.get({ colId: params.columnId }); - req.ncProjectId = column?.base_id; + req.ncBaseId = column?.base_id; } else if (params.filterId) { const filter = await Filter.get(params.filterId); - req.ncProjectId = filter?.base_id; + req.ncBaseId = filter?.base_id; } else if (params.filterParentId) { const filter = await Filter.get(params.filterParentId); - req.ncProjectId = filter?.base_id; + req.ncBaseId = filter?.base_id; } else if (params.sortId) { const sort = await Sort.get(params.sortId); - req.ncProjectId = sort?.base_id; + req.ncBaseId = sort?.base_id; } else if (params.syncId) { const syncSource = await SyncSource.get(req.params.syncId); - req.ncProjectId = syncSource.base_id; + req.ncBaseId = syncSource.base_id; } // extract fk_model_id from query params only if it's audit post endpoint else if ( @@ -139,7 +139,7 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate { const model = await Model.getByIdOrName({ id: req.body.fk_model_id, }); - req.ncProjectId = model?.base_id; + req.ncBaseId = model?.base_id; } // extract fk_model_id from query params only if it's audit get endpoint else if ( @@ -155,7 +155,7 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate { const model = await Model.getByIdOrName({ id: req.query?.fk_model_id, }); - req.ncProjectId = model?.base_id; + req.ncBaseId = model?.base_id; } // extract base id from query params only if it's userMe endpoint or webhook plugin list else if ( @@ -168,7 +168,7 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate { ].some((userMePath) => req.route.path === userMePath) && req.query.base_id ) { - req.ncProjectId = req.query.base_id; + req.ncBaseId = req.query.base_id; } next(); diff --git a/packages/nocodb/src/strategies/authtoken.strategy/authtoken.strategy.ts b/packages/nocodb/src/strategies/authtoken.strategy/authtoken.strategy.ts index 83c4fd48cc..f666ac1b10 100644 --- a/packages/nocodb/src/strategies/authtoken.strategy/authtoken.strategy.ts +++ b/packages/nocodb/src/strategies/authtoken.strategy/authtoken.strategy.ts @@ -31,7 +31,7 @@ export class AuthTokenStrategy extends PassportStrategy(Strategy, 'authtoken') { const dbUser: Record = await User.getWithRoles( apiToken.fk_user_id, { - baseId: req['ncProjectId'], + baseId: req['ncBaseId'], ...(req['ncWorkspaceId'] ? { workspaceId: req['ncWorkspaceId'] } : {}), diff --git a/packages/nocodb/src/strategies/base-view.strategy/base-view.strategy.ts b/packages/nocodb/src/strategies/base-view.strategy/base-view.strategy.ts index 022fc3b67b..4cb32d36b8 100644 --- a/packages/nocodb/src/strategies/base-view.strategy/base-view.strategy.ts +++ b/packages/nocodb/src/strategies/base-view.strategy/base-view.strategy.ts @@ -17,7 +17,7 @@ export class BaseViewStrategy extends PassportStrategy(Strategy, 'base-view') { ); // validate base id - if (!sharedProject || req.ncProjectId !== sharedProject.id) { + if (!sharedProject || req.ncBaseId !== sharedProject.id) { return callback(new UnauthorizedException()); } diff --git a/packages/nocodb/src/strategies/google.strategy/google.strategy.ts b/packages/nocodb/src/strategies/google.strategy/google.strategy.ts index f7eaea5b73..ecd43c9e66 100644 --- a/packages/nocodb/src/strategies/google.strategy/google.strategy.ts +++ b/packages/nocodb/src/strategies/google.strategy/google.strategy.ts @@ -33,8 +33,8 @@ export class GoogleStrategy extends PassportStrategy(Strategy, 'google') { const user = await User.getByEmail(email); if (user) { // if base id defined extract base level roles - if (req.ncProjectId) { - BaseUser.get(req.ncProjectId, user.id) + if (req.ncBaseId) { + BaseUser.get(req.ncBaseId, user.id) .then(async (baseUser) => { user.roles = baseUser?.roles || user.roles; // + (user.roles ? `,${user.roles}` : ''); diff --git a/packages/nocodb/src/strategies/jwt.strategy.ts b/packages/nocodb/src/strategies/jwt.strategy.ts index cea4337577..74db4e8588 100644 --- a/packages/nocodb/src/strategies/jwt.strategy.ts +++ b/packages/nocodb/src/strategies/jwt.strategy.ts @@ -28,7 +28,7 @@ export class JwtStrategy extends PassportStrategy(Strategy) { return User.getWithRoles(user.id, { user, - baseId: req.ncProjectId, + baseId: req.ncBaseId, }); } } diff --git a/packages/nocodb/src/types/express.d.ts b/packages/nocodb/src/types/express.d.ts index dc68aac2cc..a0748427d3 100644 --- a/packages/nocodb/src/types/express.d.ts +++ b/packages/nocodb/src/types/express.d.ts @@ -2,7 +2,7 @@ import type { UserType } from 'nocodb-sdk'; declare module 'express-serve-static-core' { interface Request { ncWorkspaceId?: string; - ncProjectId?: string; + ncBaseId?: string; user: UserType & { base_roles?: Record; workspace_roles?: Record;