Browse Source

fix: miscellaneous bug fixes

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5444/head
Pranav C 2 years ago
parent
commit
81fbb4d60d
  1. 8
      packages/nocodb-nest/src/app.module.ts
  2. 6
      packages/nocodb-nest/src/middlewares/extract-project-id/extract-project-id.middleware.ts
  3. 2
      packages/nocodb-nest/src/modules/api-docs/api-docs.controller.ts
  4. 8
      packages/nocodb-nest/src/modules/attachments/attachments.controller.ts
  5. 2
      packages/nocodb-nest/src/modules/audits/audits.controller.ts
  6. 2
      packages/nocodb-nest/src/modules/bases/bases.controller.ts
  7. 2
      packages/nocodb-nest/src/modules/caches/caches.controller.ts
  8. 2
      packages/nocodb-nest/src/modules/columns/columns.controller.ts
  9. 10
      packages/nocodb-nest/src/modules/datas/bulk-data-alias/bulk-data-alias.controller.ts
  10. 8
      packages/nocodb-nest/src/modules/datas/data-alias-export/data-alias-export.controller.ts
  11. 8
      packages/nocodb-nest/src/modules/datas/data-alias-nested/data-alias-nested.controller.ts
  12. 4
      packages/nocodb-nest/src/modules/datas/data-alias.controller.spec.ts
  13. 13
      packages/nocodb-nest/src/modules/datas/data-alias.controller.ts
  14. 2
      packages/nocodb-nest/src/modules/datas/datas.controller.ts
  15. 2
      packages/nocodb-nest/src/modules/datas/datas.module.ts
  16. 7
      packages/nocodb-nest/src/modules/datas/old-datas/old-datas.controller.ts
  17. 2
      packages/nocodb-nest/src/modules/form-columns/form-columns.controller.ts
  18. 2
      packages/nocodb-nest/src/modules/forms/forms.controller.ts
  19. 2
      packages/nocodb-nest/src/modules/galleries/galleries.controller.ts
  20. 2
      packages/nocodb-nest/src/modules/grid-columns/grid-columns.controller.ts
  21. 2
      packages/nocodb-nest/src/modules/grids/grids.controller.ts
  22. 3
      packages/nocodb-nest/src/modules/hook-filters/hook-filters.controller.ts
  23. 2
      packages/nocodb-nest/src/modules/hooks/hooks.controller.ts
  24. 2
      packages/nocodb-nest/src/modules/import/import.controller.ts
  25. 2
      packages/nocodb-nest/src/modules/kanbans/kanbans.controller.ts
  26. 2
      packages/nocodb-nest/src/modules/maps/maps.controller.ts
  27. 2
      packages/nocodb-nest/src/modules/meta-diffs/meta-diffs.controller.ts
  28. 2
      packages/nocodb-nest/src/modules/model-visibilities/model-visibilities.controller.ts
  29. 2
      packages/nocodb-nest/src/modules/org-lcense/org-lcense.controller.ts
  30. 2
      packages/nocodb-nest/src/modules/org-tokens/org-tokens.controller.ts
  31. 2
      packages/nocodb-nest/src/modules/org-users/org-users.controller.ts
  32. 2
      packages/nocodb-nest/src/modules/plugins/plugins.controller.ts
  33. 2
      packages/nocodb-nest/src/modules/project-users/project-users.controller.ts
  34. 7
      packages/nocodb-nest/src/modules/projects/projects.service.ts
  35. 2
      packages/nocodb-nest/src/modules/public-datas-export/public-datas-export.controller.ts
  36. 2
      packages/nocodb-nest/src/modules/public-datas/public-datas.controller.ts
  37. 2
      packages/nocodb-nest/src/modules/public-metas/public-metas.controller.ts
  38. 2
      packages/nocodb-nest/src/modules/shared-bases/shared-bases.controller.ts
  39. 2
      packages/nocodb-nest/src/modules/sync/sync.controller.ts
  40. 2
      packages/nocodb-nest/src/modules/test/test.controller.ts
  41. 2
      packages/nocodb-nest/src/modules/utils/utils.controller.ts
  42. 2
      packages/nocodb-nest/src/modules/view-columns/view-columns.controller.ts
  43. 2
      packages/nocodb-nest/src/strategies/jwt.strategy.ts
  44. 2
      packages/nocodb-nest/src/utils/extractRolesObj.ts

8
packages/nocodb-nest/src/app.module.ts

@ -4,7 +4,7 @@ import { AuthModule } from './modules/auth/auth.module';
import { ExtractProjectIdMiddleware } from './middlewares/extract-project-id/extract-project-id.middleware'; import { ExtractProjectIdMiddleware } from './middlewares/extract-project-id/extract-project-id.middleware';
import { UsersModule } from './modules/users/users.module'; import { UsersModule } from './modules/users/users.module';
import { MetaService } from './meta/meta.service'; import { MetaService } from './meta/meta.service';
import { LocalStrategy } from './strategies/local.strategy'; // import { LocalStrategy } from './strategies/local.strategy';
import { UtilsModule } from './modules/utils/utils.module'; import { UtilsModule } from './modules/utils/utils.module';
import { ProjectsModule } from './modules/projects/projects.module'; import { ProjectsModule } from './modules/projects/projects.module';
import { JwtStrategy } from './strategies/jwt.strategy'; import { JwtStrategy } from './strategies/jwt.strategy';
@ -95,8 +95,8 @@ import { PluginsModule } from './modules/plugins/plugins.module';
}) })
export class AppModule { export class AppModule {
configure(consumer: MiddlewareConsumer) { configure(consumer: MiddlewareConsumer) {
consumer // consumer
.apply(ExtractProjectIdMiddleware) // .apply(ExtractProjectIdMiddleware)
.forRoutes({ path: '*', method: RequestMethod.ALL }); // .forRoutes({ path: '*', method: RequestMethod.ALL });
} }
} }

6
packages/nocodb-nest/src/middlewares/extract-project-id/extract-project-id.middleware.ts

@ -189,7 +189,9 @@ export class ExtractProjectIdMiddleware implements NestMiddleware, CanActivate {
await this.use( await this.use(
context.switchToHttp().getRequest(), context.switchToHttp().getRequest(),
context.switchToHttp().getResponse(), context.switchToHttp().getResponse(),
() => {}, () => {
console.log('next');
},
); );
return true; return true;
} }
@ -222,7 +224,7 @@ export class AclMiddleware implements NestInterceptor {
const roles: Record<string, boolean> = extractRolesObj(req.user.roles); const roles: Record<string, boolean> = extractRolesObj(req.user.roles);
if (req?.session?.passport?.user?.is_api_token && blockApiTokenAccess) { if (req?.user?.is_api_token && blockApiTokenAccess) {
NcError.forbidden('Not allowed with API token'); NcError.forbidden('Not allowed with API token');
} }
if ( if (

2
packages/nocodb-nest/src/modules/api-docs/api-docs.controller.ts

@ -3,7 +3,7 @@ import { ApiDocsService } from './api-docs.service';
import getSwaggerHtml from './template/swaggerHtml'; import getSwaggerHtml from './template/swaggerHtml';
import getRedocHtml from './template/redocHtml'; import getRedocHtml from './template/redocHtml';
@Controller('api-docs') @Controller()
export class ApiDocsController { export class ApiDocsController {
constructor(private readonly apiDocsService: ApiDocsService) {} constructor(private readonly apiDocsService: ApiDocsService) {}

8
packages/nocodb-nest/src/modules/attachments/attachments.controller.ts

@ -7,7 +7,9 @@ import {
Query, Query,
Request, Request,
Response, Response,
UseInterceptors,
} from '@nestjs/common'; } from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { OrgUserRoles, ProjectRoles } from 'nocodb-sdk'; import { OrgUserRoles, ProjectRoles } from 'nocodb-sdk';
import path from 'path'; import path from 'path';
import { NcError } from '../../helpers/catchError'; import { NcError } from '../../helpers/catchError';
@ -45,7 +47,7 @@ const isUploadAllowedMw = async (req: Request, _res: Response, next: any) => {
NcError.badRequest('Upload not allowed'); NcError.badRequest('Upload not allowed');
}; };
@Controller('attachments') @Controller()
export class AttachmentsController { export class AttachmentsController {
constructor(private readonly attachmentsService: AttachmentsService) {} constructor(private readonly attachmentsService: AttachmentsService) {}
@ -64,6 +66,7 @@ export class AttachmentsController {
// ] // ]
// ); // );
) )
@UseInterceptors(FileInterceptor('files'))
async upload(@Request() req: any, @Query('path') path: string) { async upload(@Request() req: any, @Query('path') path: string) {
const attachments = await this.attachmentsService.upload({ const attachments = await this.attachmentsService.upload({
files: (req as any).files, files: (req as any).files,
@ -94,8 +97,7 @@ export class AttachmentsController {
// , getCacheMiddleware(), catchError(fileRead)); // , getCacheMiddleware(), catchError(fileRead));
@Get('/download/:filename(*)') @Get('/download/:filename(*)')
// This route will match any URL that starts with // This route will match any URL that starts with
async fileRead(@Param('filename') filename: string async fileRead(@Param('filename') filename: string, @Response() res) {
, @Response() res) {
try { try {
const { img, type } = await this.attachmentsService.fileRead({ const { img, type } = await this.attachmentsService.fileRead({
path: path.join('nc', 'uploads', filename), path: path.join('nc', 'uploads', filename),

2
packages/nocodb-nest/src/modules/audits/audits.controller.ts

@ -13,7 +13,7 @@ import { Acl } from '../../middlewares/extract-project-id/extract-project-id.mid
import { Audit } from '../../models'; import { Audit } from '../../models';
import { AuditsService } from './audits.service'; import { AuditsService } from './audits.service';
@Controller('audits') @Controller()
export class AuditsController { export class AuditsController {
constructor(private readonly auditsService: AuditsService) {} constructor(private readonly auditsService: AuditsService) {}

2
packages/nocodb-nest/src/modules/bases/bases.controller.ts

@ -17,7 +17,7 @@ import {
import { BasesService } from './bases.service'; import { BasesService } from './bases.service';
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
@Controller('bases') @Controller()
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) @UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class BasesController { export class BasesController {
constructor(private readonly basesService: BasesService) {} constructor(private readonly basesService: BasesService) {}

2
packages/nocodb-nest/src/modules/caches/caches.controller.ts

@ -2,7 +2,7 @@ import { Controller, Delete, Get } from '@nestjs/common';
import { Acl } from '../../middlewares/extract-project-id/extract-project-id.middleware'; import { Acl } from '../../middlewares/extract-project-id/extract-project-id.middleware';
import { CachesService } from './caches.service'; import { CachesService } from './caches.service';
@Controller('caches') @Controller()
export class CachesController { export class CachesController {
constructor(private readonly cachesService: CachesService) {} constructor(private readonly cachesService: CachesService) {}

2
packages/nocodb-nest/src/modules/columns/columns.controller.ts

@ -17,7 +17,7 @@ import {
import { ColumnsService } from './columns.service'; import { ColumnsService } from './columns.service';
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
@Controller('columns') @Controller()
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) @UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class ColumnsController { export class ColumnsController {
constructor(private readonly columnsService: ColumnsService) {} constructor(private readonly columnsService: ColumnsService) {}

10
packages/nocodb-nest/src/modules/datas/bulk-data-alias/bulk-data-alias.controller.ts

@ -5,12 +5,14 @@ import {
Request, Request,
Body, Body,
Patch, Patch,
Delete, Delete, UseGuards,
} from '@nestjs/common'; } from '@nestjs/common'
import { Acl } from '../../../middlewares/extract-project-id/extract-project-id.middleware'; import { Acl, ExtractProjectIdMiddleware } from '../../../middlewares/extract-project-id/extract-project-id.middleware'
import { BulkDataAliasService } from './bulk-data-alias.service'; import { BulkDataAliasService } from './bulk-data-alias.service';
import { AuthGuard } from '@nestjs/passport';
@Controller('bulk-data-alias') @Controller()
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class BulkDataAliasController { export class BulkDataAliasController {
constructor(private bulkDataAliasService: BulkDataAliasService) {} constructor(private bulkDataAliasService: BulkDataAliasService) {}

8
packages/nocodb-nest/src/modules/datas/data-alias-export/data-alias-export.controller.ts

@ -1,11 +1,13 @@
import { Controller, Get, Request, Response } from '@nestjs/common'; import { Controller, Get, Request, Response, UseGuards } from '@nestjs/common'
import { Acl } from '../../../middlewares/extract-project-id/extract-project-id.middleware'; import { Acl, ExtractProjectIdMiddleware } from '../../../middlewares/extract-project-id/extract-project-id.middleware'
import { View } from '../../../models'; import { View } from '../../../models';
import { DatasService } from '../datas.service'; import { DatasService } from '../datas.service';
import { extractCsvData, extractXlsxData } from '../helpers'; import { extractCsvData, extractXlsxData } from '../helpers';
import * as XLSX from 'xlsx'; import * as XLSX from 'xlsx';
import { AuthGuard } from '@nestjs/passport';
@Controller('data-alias-export') @Controller()
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class DataAliasExportController { export class DataAliasExportController {
constructor(private datasService: DatasService) {} constructor(private datasService: DatasService) {}

8
packages/nocodb-nest/src/modules/datas/data-alias-nested/data-alias-nested.controller.ts

@ -1,8 +1,10 @@
import { Controller, Delete, Get, Param, Post, Request } from '@nestjs/common'; import { Controller, Delete, Get, Param, Post, Request, UseGuards } from '@nestjs/common'
import { Acl } from '../../../middlewares/extract-project-id/extract-project-id.middleware'; import { Acl, ExtractProjectIdMiddleware } from '../../../middlewares/extract-project-id/extract-project-id.middleware'
import { DataAliasNestedService } from './data-alias-nested.service'; import { DataAliasNestedService } from './data-alias-nested.service';
import { AuthGuard } from '@nestjs/passport';
@Controller('data-alias-nested') @Controller()
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
class DataAliasNestedController { class DataAliasNestedController {
constructor(private dataAliasNestedService: DataAliasNestedService) {} constructor(private dataAliasNestedService: DataAliasNestedService) {}

4
packages/nocodb-nest/src/modules/datas/data-alias.controller.spec.ts

@ -1,6 +1,6 @@
import { Test, TestingModule } from '@nestjs/testing'; import { Test, TestingModule } from '@nestjs/testing';
import { DataAliasController } from './data-alias.controller'; import { DataAliasController } from './data-alias.controller';
import { DataAliasService } from '../data-alias/data-alias.service'; import { DatasService } from './datas.service'
describe('DataAliasController', () => { describe('DataAliasController', () => {
let controller: DataAliasController; let controller: DataAliasController;
@ -8,7 +8,7 @@ describe('DataAliasController', () => {
beforeEach(async () => { beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({ const module: TestingModule = await Test.createTestingModule({
controllers: [DataAliasController], controllers: [DataAliasController],
providers: [DataAliasService], providers: [DatasService],
}).compile(); }).compile();
controller = module.get<DataAliasController>(DataAliasController); controller = module.get<DataAliasController>(DataAliasController);

13
packages/nocodb-nest/src/modules/datas/data-alias.controller.ts

@ -7,13 +7,15 @@ import {
Patch, Patch,
Post, Post,
Request, Request,
Response, Response, UseGuards,
} from '@nestjs/common'; } from '@nestjs/common'
import { parseHrtimeToSeconds } from '../../helpers'; import { parseHrtimeToSeconds } from '../../helpers';
import { Acl } from '../../middlewares/extract-project-id/extract-project-id.middleware'; import { Acl, ExtractProjectIdMiddleware } from '../../middlewares/extract-project-id/extract-project-id.middleware'
import { DatasService } from './datas.service'; import { DatasService } from './datas.service';
import { AuthGuard } from '@nestjs/passport';
@Controller('data-alias') @Controller()
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class DataAliasController { export class DataAliasController {
constructor(private readonly datasService: DatasService) {} constructor(private readonly datasService: DatasService) {}
@ -38,9 +40,8 @@ export class DataAliasController {
viewName: viewName, viewName: viewName,
}); });
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(startTime)); const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(startTime));
res.setHeader('xc-db-response', elapsedSeconds); res.setHeader('xc-db-response', elapsedSeconds);
return responseData; res.json(responseData);
} }
@Get([ @Get([

2
packages/nocodb-nest/src/modules/datas/datas.controller.ts

@ -11,7 +11,7 @@ import {
import { Acl } from '../../middlewares/extract-project-id/extract-project-id.middleware'; import { Acl } from '../../middlewares/extract-project-id/extract-project-id.middleware';
import { DatasService } from './datas.service'; import { DatasService } from './datas.service';
@Controller('datas') @Controller()
export class DatasController { export class DatasController {
constructor(private readonly datasService: DatasService) {} constructor(private readonly datasService: DatasService) {}

2
packages/nocodb-nest/src/modules/datas/datas.module.ts

@ -10,10 +10,10 @@ import { DataAliasNestedService } from './data-alias-nested/data-alias-nested.se
@Module({ @Module({
controllers: [ controllers: [
DataAliasController,
DatasController, DatasController,
BulkDataAliasController, BulkDataAliasController,
DataAliasExportController, DataAliasExportController,
DataAliasController,
OldDatasController, OldDatasController,
], ],
providers: [DatasService, BulkDataAliasService, DataAliasNestedService] providers: [DatasService, BulkDataAliasService, DataAliasNestedService]

7
packages/nocodb-nest/src/modules/datas/old-datas/old-datas.controller.ts

@ -1,4 +1,7 @@
import { Controller } from '@nestjs/common'; import { Controller, UseGuards } from '@nestjs/common'
import { ExtractProjectIdMiddleware } from '../../../middlewares/extract-project-id/extract-project-id.middleware'
import { AuthGuard } from '@nestjs/passport'
@Controller('old-datas') @Controller()
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class OldDatasController {} export class OldDatasController {}

2
packages/nocodb-nest/src/modules/form-columns/form-columns.controller.ts

@ -8,7 +8,7 @@ import { AuthGuard } from '@nestjs/passport';
class FormColumnUpdateReqType {} class FormColumnUpdateReqType {}
@Controller('form-columns') @Controller()
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) @UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class FormColumnsController { export class FormColumnsController {
constructor(private readonly formColumnsService: FormColumnsService) {} constructor(private readonly formColumnsService: FormColumnsService) {}

2
packages/nocodb-nest/src/modules/forms/forms.controller.ts

@ -15,7 +15,7 @@ import {
import { FormsService } from './forms.service'; import { FormsService } from './forms.service';
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
@Controller('forms') @Controller()
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) @UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class FormsController { export class FormsController {
constructor(private readonly formsService: FormsService) {} constructor(private readonly formsService: FormsService) {}

2
packages/nocodb-nest/src/modules/galleries/galleries.controller.ts

@ -15,7 +15,7 @@ import {
import { GalleriesService } from './galleries.service'; import { GalleriesService } from './galleries.service';
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
@Controller('galleries') @Controller()
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) @UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class GalleriesController { export class GalleriesController {
constructor(private readonly galleriesService: GalleriesService) {} constructor(private readonly galleriesService: GalleriesService) {}

2
packages/nocodb-nest/src/modules/grid-columns/grid-columns.controller.ts

@ -7,7 +7,7 @@ import {
import { GridColumnsService } from './grid-columns.service'; import { GridColumnsService } from './grid-columns.service';
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
@Controller('grid-columns') @Controller()
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) @UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class GridColumnsController { export class GridColumnsController {
constructor(private readonly gridColumnsService: GridColumnsService) {} constructor(private readonly gridColumnsService: GridColumnsService) {}

2
packages/nocodb-nest/src/modules/grids/grids.controller.ts

@ -14,7 +14,7 @@ import {
import { GridsService } from './grids.service'; import { GridsService } from './grids.service';
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
@Controller('grids') @Controller()
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) @UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class GridsController { export class GridsController {
get '/api/v1/db/meta/tables/:tableId/grids/'() { get '/api/v1/db/meta/tables/:tableId/grids/'() {

3
packages/nocodb-nest/src/modules/hook-filters/hook-filters.controller.ts

@ -1,8 +1,7 @@
import { Controller } from '@nestjs/common'; import { Controller } from '@nestjs/common';
import { HookFiltersService } from './hook-filters.service'; import { HookFiltersService } from './hook-filters.service';
@Controller('hook-filters') @Controller()
export class HookFiltersController { export class HookFiltersController {
constructor(private readonly hookFiltersService: HookFiltersService) {} constructor(private readonly hookFiltersService: HookFiltersService) {}
} }

2
packages/nocodb-nest/src/modules/hooks/hooks.controller.ts

@ -18,7 +18,7 @@ import {
import { HooksService } from './hooks.service'; import { HooksService } from './hooks.service';
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
@Controller('hooks') @Controller()
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) @UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class HooksController { export class HooksController {
constructor(private readonly hooksService: HooksService) {} constructor(private readonly hooksService: HooksService) {}

2
packages/nocodb-nest/src/modules/import/import.controller.ts

@ -77,7 +77,7 @@ export default (
delete jobs[payload?.id]; delete jobs[payload?.id];
}); });
}; };
@Controller('import') @Controller()
export class ImportController { export class ImportController {
constructor(private readonly importService: ImportService) {} constructor(private readonly importService: ImportService) {}

2
packages/nocodb-nest/src/modules/kanbans/kanbans.controller.ts

@ -15,7 +15,7 @@ import {
import { KanbansService } from './kanbans.service'; import { KanbansService } from './kanbans.service';
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
@Controller('kanbans') @Controller()
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) @UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class KanbansController { export class KanbansController {
constructor(private readonly kanbansService: KanbansService) {} constructor(private readonly kanbansService: KanbansService) {}

2
packages/nocodb-nest/src/modules/maps/maps.controller.ts

@ -15,7 +15,7 @@ import {
import { MapsService } from './maps.service'; import { MapsService } from './maps.service';
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
@Controller('maps') @Controller()
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) @UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class MapsController { export class MapsController {
constructor(private readonly mapsService: MapsService) {} constructor(private readonly mapsService: MapsService) {}

2
packages/nocodb-nest/src/modules/meta-diffs/meta-diffs.controller.ts

@ -6,7 +6,7 @@ import {
import { MetaDiffsService } from './meta-diffs.service'; import { MetaDiffsService } from './meta-diffs.service';
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
@Controller('meta-diffs') @Controller()
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) @UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class MetaDiffsController { export class MetaDiffsController {
constructor(private readonly metaDiffsService: MetaDiffsService) {} constructor(private readonly metaDiffsService: MetaDiffsService) {}

2
packages/nocodb-nest/src/modules/model-visibilities/model-visibilities.controller.ts

@ -14,7 +14,7 @@ import {
import { ModelVisibilitiesService } from './model-visibilities.service'; import { ModelVisibilitiesService } from './model-visibilities.service';
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
@Controller('model-visibilities') @Controller()
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) @UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class ModelVisibilitiesController { export class ModelVisibilitiesController {
constructor( constructor(

2
packages/nocodb-nest/src/modules/org-lcense/org-lcense.controller.ts

@ -3,7 +3,7 @@ import { OrgUserRoles } from 'nocodb-sdk';
import { Acl } from '../../middlewares/extract-project-id/extract-project-id.middleware'; import { Acl } from '../../middlewares/extract-project-id/extract-project-id.middleware';
import { OrgLcenseService } from './org-lcense.service'; import { OrgLcenseService } from './org-lcense.service';
@Controller('org-lcense') @Controller()
export class OrgLcenseController { export class OrgLcenseController {
constructor(private readonly orgLcenseService: OrgLcenseService) {} constructor(private readonly orgLcenseService: OrgLcenseService) {}

2
packages/nocodb-nest/src/modules/org-tokens/org-tokens.controller.ts

@ -19,7 +19,7 @@ import { OrgTokensService } from './org-tokens.service';
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) @UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
@Controller('org-tokens') @Controller()
export class OrgTokensController { export class OrgTokensController {
constructor( constructor(
private readonly orgTokensService: OrgTokensService, private readonly orgTokensService: OrgTokensService,

2
packages/nocodb-nest/src/modules/org-users/org-users.controller.ts

@ -14,7 +14,7 @@ import { Acl } from '../../middlewares/extract-project-id/extract-project-id.mid
import { User } from '../../models'; import { User } from '../../models';
import { OrgUsersService } from './org-users.service'; import { OrgUsersService } from './org-users.service';
@Controller('org-users') @Controller()
export class OrgUsersController { export class OrgUsersController {
constructor(private readonly orgUsersService: OrgUsersService) {} constructor(private readonly orgUsersService: OrgUsersService) {}

2
packages/nocodb-nest/src/modules/plugins/plugins.controller.ts

@ -10,7 +10,7 @@ const blockInCloudMw = (_req, res, next) => {
} else next(); } else next();
}; };
@Controller('plugins') @Controller()
export class PluginsController { export class PluginsController {
constructor(private readonly pluginsService: PluginsService) {} constructor(private readonly pluginsService: PluginsService) {}

2
packages/nocodb-nest/src/modules/project-users/project-users.controller.ts

@ -18,7 +18,7 @@ import { ProjectUsersService } from './project-users.service';
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) @UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
@Controller('project-users') @Controller()
export class ProjectUsersController { export class ProjectUsersController {
constructor(private readonly projectUsersService: ProjectUsersService) {} constructor(private readonly projectUsersService: ProjectUsersService) {}

7
packages/nocodb-nest/src/modules/projects/projects.service.ts

@ -11,14 +11,17 @@ import syncMigration from '../../helpers/syncMigration';
import { Project, ProjectUser } from '../../models'; import { Project, ProjectUser } from '../../models';
import { T } from 'nc-help'; import { T } from 'nc-help';
import Noco from '../../Noco'; import Noco from '../../Noco';
import extractRolesObj from '../../utils/extractRolesObj'
import NcConfigFactory from '../../utils/NcConfigFactory'; import NcConfigFactory from '../../utils/NcConfigFactory';
const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 4); const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 4);
@Injectable() @Injectable()
export class ProjectsService { export class ProjectsService {
async list(param: { user: { id: string; roles: string }; query?: any }) { async list(param: { user: { id: string; roles: Record<string, boolean> }; query?: any }) {
const projects = param.user?.roles?.includes(OrgUserRoles.SUPER_ADMIN) const projects = extractRolesObj(param.user?.roles)[
OrgUserRoles.SUPER_ADMIN
]
? await Project.list(param.query) ? await Project.list(param.query)
: await ProjectUser.getProjectsList(param.user.id, param.query); : await ProjectUser.getProjectsList(param.user.id, param.query);

2
packages/nocodb-nest/src/modules/public-datas-export/public-datas-export.controller.ts

@ -17,7 +17,7 @@ import { nocoExecute } from 'nc-help';
import papaparse from 'papaparse'; import papaparse from 'papaparse';
import { serializeCellValue } from '../datas/helpers'; import { serializeCellValue } from '../datas/helpers';
@Controller('public-datas-export') @Controller()
export class PublicDatasExportController { export class PublicDatasExportController {
constructor( constructor(
private readonly publicDatasExportService: PublicDatasExportService, private readonly publicDatasExportService: PublicDatasExportService,

2
packages/nocodb-nest/src/modules/public-datas/public-datas.controller.ts

@ -1,7 +1,7 @@
import { Controller, Get, Param, Post, Request } from '@nestjs/common'; import { Controller, Get, Param, Post, Request } from '@nestjs/common';
import { PublicDatasService } from './public-datas.service'; import { PublicDatasService } from './public-datas.service';
@Controller('public-datas') @Controller()
export class PublicDatasController { export class PublicDatasController {
constructor(private readonly publicDatasService: PublicDatasService) {} constructor(private readonly publicDatasService: PublicDatasService) {}

2
packages/nocodb-nest/src/modules/public-metas/public-metas.controller.ts

@ -1,7 +1,7 @@
import { Controller, Get, Request, Param } from '@nestjs/common'; import { Controller, Get, Request, Param } from '@nestjs/common';
import { PublicMetasService } from './public-metas.service'; import { PublicMetasService } from './public-metas.service';
@Controller('public-metas') @Controller()
export class PublicMetasController { export class PublicMetasController {
constructor(private readonly publicMetasService: PublicMetasService) {} constructor(private readonly publicMetasService: PublicMetasService) {}

2
packages/nocodb-nest/src/modules/shared-bases/shared-bases.controller.ts

@ -13,7 +13,7 @@ import {
import { SharedBasesService } from './shared-bases.service'; import { SharedBasesService } from './shared-bases.service';
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
@Controller('shared-bases') @Controller()
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) @UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class SharedBasesController { export class SharedBasesController {
constructor(private readonly sharedBasesService: SharedBasesService) {} constructor(private readonly sharedBasesService: SharedBasesService) {}

2
packages/nocodb-nest/src/modules/sync/sync.controller.ts

@ -11,7 +11,7 @@ import {
import { Acl } from '../../middlewares/extract-project-id/extract-project-id.middleware'; import { Acl } from '../../middlewares/extract-project-id/extract-project-id.middleware';
import { SyncService } from './sync.service'; import { SyncService } from './sync.service';
@Controller('sync') @Controller()
export class SyncController { export class SyncController {
constructor(private readonly syncService: SyncService) {} constructor(private readonly syncService: SyncService) {}

2
packages/nocodb-nest/src/modules/test/test.controller.ts

@ -2,7 +2,7 @@ import { Controller, Post, Req } from '@nestjs/common';
import { TestService } from './test.service'; import { TestService } from './test.service';
import { TestResetService } from './TestResetService'; import { TestResetService } from './TestResetService';
@Controller('test') @Controller()
export class TestController { export class TestController {
constructor(private readonly testService: TestService) {} constructor(private readonly testService: TestService) {}

2
packages/nocodb-nest/src/modules/utils/utils.controller.ts

@ -1,7 +1,7 @@
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { UtilsService } from './utils.service'; import { UtilsService } from './utils.service';
@Controller('/') @Controller()
export class UtilsController { export class UtilsController {
constructor(private readonly utilsService: UtilsService) {} constructor(private readonly utilsService: UtilsService) {}

2
packages/nocodb-nest/src/modules/view-columns/view-columns.controller.ts

@ -16,7 +16,7 @@ import {
import { ViewColumnsService } from './view-columns.service'; import { ViewColumnsService } from './view-columns.service';
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
@Controller('view-columns') @Controller()
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) @UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class ViewColumnsController { export class ViewColumnsController {
constructor(private readonly viewColumnsService: ViewColumnsService) {} constructor(private readonly viewColumnsService: ViewColumnsService) {}

2
packages/nocodb-nest/src/strategies/jwt.strategy.ts

@ -26,7 +26,7 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
// todo: improve this // todo: improve this
if ( if (
req.ncProjectId && req.ncProjectId &&
jwtPayload.roles?.split(',').includes(OrgUserRoles.SUPER_ADMIN) extractRolesObj(jwtPayload.roles)[OrgUserRoles.SUPER_ADMIN]
) { ) {
return User.getByEmail(jwtPayload?.email).then(async (user) => { return User.getByEmail(jwtPayload?.email).then(async (user) => {
return { return {

2
packages/nocodb-nest/src/utils/extractRolesObj.ts

@ -1,4 +1,4 @@
export default (roles: string | string[]) => { export default (roles) => {
if(!roles) return {}; if(!roles) return {};
if(typeof roles === 'object' && !Array.isArray(roles)) return roles; if(typeof roles === 'object' && !Array.isArray(roles)) return roles;

Loading…
Cancel
Save