Browse Source

refactor: include request object in app-hook payload

pull/6894/head
Pranav C 1 year ago
parent
commit
f66877f06b
  1. 2
      packages/nocodb/src/controllers/api-tokens.controller.ts
  2. 2
      packages/nocodb/src/controllers/attachments-secure.controller.ts
  3. 10
      packages/nocodb/src/controllers/attachments.controller.ts
  4. 3
      packages/nocodb/src/controllers/bases.controller.ts
  5. 7
      packages/nocodb/src/controllers/filters.controller.ts
  6. 5
      packages/nocodb/src/controllers/form-columns.controller.ts
  7. 6
      packages/nocodb/src/controllers/forms.controller.ts
  8. 4
      packages/nocodb/src/controllers/galleries.controller.ts
  9. 5
      packages/nocodb/src/controllers/grid-columns.controller.ts
  10. 10
      packages/nocodb/src/controllers/grids.controller.ts
  11. 15
      packages/nocodb/src/controllers/hooks.controller.ts
  12. 4
      packages/nocodb/src/controllers/kanbans.controller.ts
  13. 4
      packages/nocodb/src/controllers/maps.controller.ts
  14. 3
      packages/nocodb/src/controllers/model-visibilities.controller.ts
  15. 2
      packages/nocodb/src/controllers/org-tokens.controller.ts
  16. 10
      packages/nocodb/src/controllers/plugins.controller.ts
  17. 6
      packages/nocodb/src/controllers/shared-bases.controller.ts
  18. 9
      packages/nocodb/src/controllers/sorts.controller.ts
  19. 4
      packages/nocodb/src/controllers/sources.controller.ts
  20. 8
      packages/nocodb/src/controllers/sync.controller.ts
  21. 1
      packages/nocodb/src/controllers/tables.controller.ts
  22. 9
      packages/nocodb/src/controllers/view-columns.controller.ts
  23. 7
      packages/nocodb/src/controllers/views.controller.ts
  24. 12
      packages/nocodb/src/modules/jobs/jobs/at-import/at-import.processor.ts
  25. 20
      packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts
  26. 6
      packages/nocodb/src/services/api-tokens.service.ts
  27. 75
      packages/nocodb/src/services/app-hooks/interfaces.ts
  28. 20
      packages/nocodb/src/services/attachments.service.ts
  29. 4
      packages/nocodb/src/services/base-users/base-users.service.ts
  30. 12
      packages/nocodb/src/services/bases.service.ts
  31. 5
      packages/nocodb/src/services/columns.service.ts
  32. 9
      packages/nocodb/src/services/filters.service.ts
  33. 5
      packages/nocodb/src/services/form-columns.service.ts
  34. 6
      packages/nocodb/src/services/forms.service.ts
  35. 5
      packages/nocodb/src/services/galleries.service.ts
  36. 5
      packages/nocodb/src/services/grid-columns.service.ts
  37. 10
      packages/nocodb/src/services/grids.service.ts
  38. 16
      packages/nocodb/src/services/hooks.service.ts
  39. 5
      packages/nocodb/src/services/kanbans.service.ts
  40. 8
      packages/nocodb/src/services/maps.service.ts
  41. 6
      packages/nocodb/src/services/meta-diffs.service.ts
  42. 2
      packages/nocodb/src/services/model-visibilities.service.ts
  43. 17
      packages/nocodb/src/services/notifications.service.ts
  44. 11
      packages/nocodb/src/services/org-tokens.service.ts
  45. 2
      packages/nocodb/src/services/org-users.service.ts
  46. 6
      packages/nocodb/src/services/plugins.service.ts
  47. 10
      packages/nocodb/src/services/shared-bases.service.ts
  48. 16
      packages/nocodb/src/services/sorts.service.ts
  49. 8
      packages/nocodb/src/services/sources.service.ts
  50. 10
      packages/nocodb/src/services/sync.service.ts
  51. 4
      packages/nocodb/src/services/tables.service.ts
  52. 19
      packages/nocodb/src/services/users/users.service.ts
  53. 7
      packages/nocodb/src/services/view-columns.service.ts
  54. 18
      packages/nocodb/src/services/views.service.ts

2
packages/nocodb/src/controllers/api-tokens.controller.ts

@ -41,6 +41,7 @@ export class ApiTokensController {
return await this.apiTokensService.apiTokenCreate({
tokenBody: body,
userId: req['user'].id,
req
});
}
@ -53,6 +54,7 @@ export class ApiTokensController {
return await this.apiTokensService.apiTokenDelete({
token,
user: req['user'],
req
});
}
}

2
packages/nocodb/src/controllers/attachments-secure.controller.ts

@ -41,6 +41,7 @@ export class AttachmentsSecureController {
const attachments = await this.attachmentsService.upload({
files: files,
path: path,
req
});
return attachments;
@ -59,6 +60,7 @@ export class AttachmentsSecureController {
const attachments = await this.attachmentsService.uploadViaURL({
urls: body,
path,
req
});
return attachments;

10
packages/nocodb/src/controllers/attachments.controller.ts

@ -36,7 +36,8 @@ export class AttachmentsController {
) {
const attachments = await this.attachmentsService.upload({
files: files,
path: req.query?.path?.toString(),
path: req.query?.path as string,
req
});
return attachments;
@ -46,13 +47,12 @@ export class AttachmentsController {
@HttpCode(200)
@UseInterceptors(UploadAllowedInterceptor)
@UseGuards(MetaApiLimiterGuard, GlobalGuard)
async uploadViaURL(
@Body() body: Array<AttachmentReqType>,
@Query('path') path: string,
) {
async uploadViaURL(@Body() body: any, @Query('path') path: string,
@Request() req: any,) {
const attachments = await this.attachmentsService.uploadViaURL({
urls: body,
path,
req
});
return attachments;

3
packages/nocodb/src/controllers/bases.controller.ts

@ -82,6 +82,7 @@ export class BasesController {
baseId,
base: body,
user: req.user,
req
});
return base;
@ -93,6 +94,7 @@ export class BasesController {
const deleted = await this.projectsService.baseSoftDelete({
baseId,
user: req.user,
req
});
return deleted;
@ -106,6 +108,7 @@ export class BasesController {
async baseCreate(@Body() baseBody: ProjectReqType, @Request() req) {
const base = await this.projectsService.baseCreate({
base: baseBody,
req,
user: req['user'],
});

7
packages/nocodb/src/controllers/filters.controller.ts

@ -50,6 +50,7 @@ export class FiltersController {
filter: body,
viewId: viewId,
user: req.user,
req
});
return filter;
}
@ -69,6 +70,7 @@ export class FiltersController {
filter: body,
hookId,
user: req.user,
req
});
return filter;
}
@ -105,7 +107,7 @@ export class FiltersController {
const filter = await this.filtersService.filterUpdate({
filterId: filterId,
filter: body,
user: req.user,
user: req.user,req
});
return filter;
}
@ -115,8 +117,9 @@ export class FiltersController {
'/api/v2/meta/filters/:filterId',
])
@Acl('filterDelete')
async filterDelete(@Param('filterId') filterId: string, @Req() _req) {
async filterDelete(@Param('filterId') filterId: string, @Req() req) {
const filter = await this.filtersService.filterDelete({
req,
filterId,
});
return filter;

5
packages/nocodb/src/controllers/form-columns.controller.ts

@ -1,4 +1,4 @@
import { Body, Controller, Param, Patch, UseGuards } from '@nestjs/common';
import { Body, Controller, Param, Patch, UseGuards , Request} from '@nestjs/common';
import { GlobalGuard } from '~/guards/global/global.guard';
import { FormColumnsService } from '~/services/form-columns.service';
import { Acl } from '~/middlewares/extract-ids/extract-ids.middleware';
@ -19,10 +19,13 @@ export class FormColumnsController {
async columnUpdate(
@Param('formViewColumnId') formViewColumnId: string,
@Body() formViewColumnbody: FormColumnUpdateReqType,
@Request() req: any,
) {
return await this.formColumnsService.columnUpdate({
formViewColumnId,
formViewColumn: formViewColumnbody,
req
});
}
}

6
packages/nocodb/src/controllers/forms.controller.ts

@ -6,6 +6,7 @@ import {
Param,
Patch,
Post,
Request,
Req,
UseGuards,
} from '@nestjs/common';
@ -44,6 +45,7 @@ export class FormsController {
body,
tableId,
user: req.user,
req
});
return view;
}
@ -52,10 +54,12 @@ export class FormsController {
'/api/v2/meta/forms/:formViewId',
])
@Acl('formViewUpdate')
async formViewUpdate(@Param('formViewId') formViewId: string, @Body() body) {
async formViewUpdate(@Param('formViewId') formViewId: string, @Body() body,
@Request() req: any,) {
return await this.formsService.formViewUpdate({
formViewId,
form: body,
req
});
}
}

4
packages/nocodb/src/controllers/galleries.controller.ts

@ -46,6 +46,7 @@ export class GalleriesController {
gallery: body,
// todo: sanitize
tableId,
req,
user: req.user,
});
}
@ -58,10 +59,13 @@ export class GalleriesController {
async galleryViewUpdate(
@Param('galleryViewId') galleryViewId: string,
@Body() body: GalleryUpdateReqType,
@Req() req: any,
) {
return await this.galleriesService.galleryViewUpdate({
galleryViewId,
gallery: body,
req
});
}
}

5
packages/nocodb/src/controllers/grid-columns.controller.ts

@ -1,4 +1,4 @@
import { Body, Controller, Get, Param, Patch, UseGuards } from '@nestjs/common';
import { Body, Controller, Get,Req, Param, Patch, UseGuards } from '@nestjs/common';
import { GridColumnReqType } from 'nocodb-sdk';
import { GlobalGuard } from '~/guards/global/global.guard';
import { GridColumnsService } from '~/services/grid-columns.service';
@ -28,10 +28,13 @@ export class GridColumnsController {
async gridColumnUpdate(
@Param('gridViewColumnId') gridViewColumnId: string,
@Body() body: GridColumnReqType,
@Req() req: any,
) {
return this.gridColumnsService.gridColumnUpdate({
gridViewColumnId,
grid: body,
req
});
}
}

10
packages/nocodb/src/controllers/grids.controller.ts

@ -28,20 +28,26 @@ export class GridsController {
async gridViewCreate(
@Param('tableId') tableId: string,
@Body() body: ViewCreateReqType,
@Req() _req: any,
@Req() req: any,
) {
const view = await this.gridsService.gridViewCreate({
grid: body,
tableId,
req,
});
return view;
}
@Patch(['/api/v1/db/meta/grids/:viewId', '/api/v2/meta/grids/:viewId'])
@Acl('gridViewUpdate')
async gridViewUpdate(@Param('viewId') viewId: string, @Body() body) {
async gridViewUpdate(
@Param('viewId') viewId: string,
@Body() body,
@Req() req: any,
) {
return await this.gridsService.gridViewUpdate({
viewId,
grid: body,
req,
});
}
}

15
packages/nocodb/src/controllers/hooks.controller.ts

@ -41,24 +41,30 @@ export class HooksController {
async hookCreate(
@Param('tableId') tableId: string,
@Body() body: HookReqType,
@Request() req: any,
) {
const hook = await this.hooksService.hookCreate({
hook: body,
tableId,
req,
});
return hook;
}
@Delete(['/api/v1/db/meta/hooks/:hookId', '/api/v2/meta/hooks/:hookId'])
@Acl('hookDelete')
async hookDelete(@Param('hookId') hookId: string) {
return await this.hooksService.hookDelete({ hookId });
async hookDelete(@Param('hookId') hookId: string, @Request() req: any) {
return await this.hooksService.hookDelete({ hookId, req });
}
@Patch(['/api/v1/db/meta/hooks/:hookId', '/api/v2/meta/hooks/:hookId'])
@Acl('hookUpdate')
async hookUpdate(@Param('hookId') hookId: string, @Body() body: HookReqType) {
return await this.hooksService.hookUpdate({ hookId, hook: body });
async hookUpdate(
@Param('hookId') hookId: string,
@Body() body: HookReqType,
@Request() req: any,
) {
return await this.hooksService.hookUpdate({ hookId, hook: body, req });
}
@Post([
@ -78,6 +84,7 @@ export class HooksController {
},
},
tableId: req.params.tableId,
req,
});
return { msg: 'The hook has been tested successfully' };
} catch (e) {

4
packages/nocodb/src/controllers/kanbans.controller.ts

@ -46,6 +46,7 @@ export class KanbansController {
tableId,
kanban: body,
user: req.user,
req
});
}
@ -57,10 +58,13 @@ export class KanbansController {
async kanbanViewUpdate(
@Param('kanbanViewId') kanbanViewId: string,
@Body() body,
@Req() req: any,
) {
return await this.kanbansService.kanbanViewUpdate({
kanbanViewId,
kanban: body,
req
});
}
}

4
packages/nocodb/src/controllers/maps.controller.ts

@ -41,6 +41,7 @@ export class MapsController {
tableId,
map: body,
user: req.user,
req
});
return view;
}
@ -50,10 +51,13 @@ export class MapsController {
async mapViewUpdate(
@Param('mapViewId') mapViewId: string,
@Body() body: MapUpdateReqType,
@Req() req: any,
) {
return await this.mapsService.mapViewUpdate({
mapViewId: mapViewId,
map: body,
req
});
}
}

3
packages/nocodb/src/controllers/model-visibilities.controller.ts

@ -2,6 +2,7 @@ import {
Body,
Controller,
Get,
Req,
HttpCode,
Param,
Post,
@ -29,10 +30,12 @@ export class ModelVisibilitiesController {
async xcVisibilityMetaSetAll(
@Param('baseId') baseId: string,
@Body() body: any,
@Req() req: any,
) {
await this.modelVisibilitiesService.xcVisibilityMetaSetAll({
visibilityRule: body,
baseId,
req
});
return { msg: 'UI ACL has been created successfully' };

2
packages/nocodb/src/controllers/org-tokens.controller.ts

@ -50,6 +50,7 @@ export class OrgTokensController {
return await this.orgTokensService.apiTokenCreate({
apiToken: body,
user: req['user'],
req
});
}
@ -63,6 +64,7 @@ export class OrgTokensController {
await this.orgTokensService.apiTokenDelete({
token,
user: req['user'],
req
});
}
}

10
packages/nocodb/src/controllers/plugins.controller.ts

@ -5,6 +5,7 @@ import {
HttpCode,
Param,
Patch,
Req,
Post,
UseGuards,
} from '@nestjs/common';
@ -47,8 +48,9 @@ export class PluginsController {
@Acl('pluginTest', {
scope: 'org',
})
async pluginTest(@Body() body: any) {
return await this.pluginsService.pluginTest({ body: body });
async pluginTest(@Body() body: any,
@Req() req: any,) {
return await this.pluginsService.pluginTest({ body: body, req });
}
@Get(['/api/v1/db/meta/plugins/:pluginId', '/api/v2/meta/plugins/:pluginId'])
@ -66,10 +68,12 @@ export class PluginsController {
@Acl('pluginUpdate', {
scope: 'org',
})
async pluginUpdate(@Body() body: any, @Param('pluginId') pluginId: string) {
async pluginUpdate(@Body() body: any, @Param('pluginId') pluginId: string,
@Req() req: any,) {
const plugin = await this.pluginsService.pluginUpdate({
pluginId: pluginId,
plugin: body,
req
});
return plugin;
}

6
packages/nocodb/src/controllers/shared-bases.controller.ts

@ -36,6 +36,7 @@ export class SharedBasesController {
roles: body?.roles,
password: body?.password,
siteUrl: req.ncSiteUrl,
req
});
return sharedBase;
@ -56,6 +57,7 @@ export class SharedBasesController {
roles: body?.roles,
password: body?.password,
siteUrl: req.ncSiteUrl,
req
});
return sharedBase;
@ -66,9 +68,11 @@ export class SharedBasesController {
'/api/v2/meta/bases/:baseId/shared',
])
@Acl('disableSharedBaseLink')
async disableSharedBaseLink(@Param('baseId') baseId: string): Promise<any> {
async disableSharedBaseLink(@Param('baseId') baseId: string,
@Request() req: any,): Promise<any> {
const sharedBase = await this.sharedBasesService.disableSharedBaseLink({
baseId,
req
});
return sharedBase;

9
packages/nocodb/src/controllers/sorts.controller.ts

@ -44,11 +44,12 @@ export class SortsController {
async sortCreate(
@Param('viewId') viewId: string,
@Body() body: SortReqType,
@Req() _req,
@Req() req,
) {
const sort = await this.sortsService.sortCreate({
sort: body,
viewId,
req
});
return sort;
}
@ -67,20 +68,22 @@ export class SortsController {
async sortUpdate(
@Param('sortId') sortId: string,
@Body() body: SortReqType,
@Req() _req,
@Req() req,
) {
const sort = await this.sortsService.sortUpdate({
sortId,
sort: body,
req
});
return sort;
}
@Delete(['/api/v1/db/meta/sorts/:sortId', '/api/v2/meta/sorts/:sortId'])
@Acl('sortDelete')
async sortDelete(@Param('sortId') sortId: string, @Req() _req) {
async sortDelete(@Param('sortId') sortId: string, @Req() req) {
const sort = await this.sortsService.sortDelete({
sortId,
req
});
return sort;
}

4
packages/nocodb/src/controllers/sources.controller.ts

@ -1,4 +1,4 @@
import { Body, Controller, Get, Param, Patch, UseGuards } from '@nestjs/common';
import { Body, Controller, Get,Request, Param, Patch, UseGuards } from '@nestjs/common';
import { BaseReqType } from 'nocodb-sdk';
import { GlobalGuard } from '~/guards/global/global.guard';
import { PagedResponseImpl } from '~/helpers/PagedResponse';
@ -37,11 +37,13 @@ export class SourcesController {
@Param('sourceId') sourceId: string,
@Param('baseId') baseId: string,
@Body() body: BaseReqType,
@Request() req: any,
) {
const source = await this.sourcesService.baseUpdate({
sourceId,
source: body,
baseId,
req
});
return source;

8
packages/nocodb/src/controllers/sync.controller.ts

@ -56,23 +56,27 @@ export class SyncController {
sourceId: sourceId,
userId: (req as any).user.id,
syncPayload: body,
req
});
}
@Delete(['/api/v1/db/meta/syncs/:syncId', '/api/v2/meta/syncs/:syncId'])
@Acl('syncSourceDelete')
async syncDelete(@Param('syncId') syncId: string) {
async syncDelete(@Param('syncId') syncId: string,@Req() req: any) {
return await this.syncService.syncDelete({
syncId: syncId,
req
});
}
@Patch(['/api/v1/db/meta/syncs/:syncId', '/api/v2/meta/syncs/:syncId'])
@Acl('syncSourceUpdate')
async syncUpdate(@Param('syncId') syncId: string, @Body() body: any) {
async syncUpdate(@Param('syncId') syncId: string, @Body() body: any,
@Req() req: any,) {
return await this.syncService.syncUpdate({
syncId: syncId,
syncPayload: body,
req
});
}
}

1
packages/nocodb/src/controllers/tables.controller.ts

@ -93,6 +93,7 @@ export class TablesController {
table: body,
baseId: req.ncProjectId,
user: req.ncProjectId,
req
});
return { msg: 'The table has been updated successfully' };
}

9
packages/nocodb/src/controllers/view-columns.controller.ts

@ -5,7 +5,7 @@ import {
HttpCode,
Param,
Patch,
Post,
Post, Req,
UseGuards,
} from '@nestjs/common';
import { ViewColumnReqType } from 'nocodb-sdk';
@ -41,11 +41,11 @@ export class ViewColumnsController {
@Acl('columnAdd')
async columnAdd(
@Param('viewId') viewId: string,
@Body() body: ViewColumnReqType,
@Body() body: ViewColumnReqType,@Req() req: any
) {
const viewColumn = await this.viewColumnsService.columnAdd({
viewId,
column: body,
column: body,req
});
return viewColumn;
}
@ -58,12 +58,13 @@ export class ViewColumnsController {
async columnUpdate(
@Param('viewId') viewId: string,
@Param('columnId') columnId: string,
@Body() body: ViewColumnReqType,
@Body() body: ViewColumnReqType,@Req() req: any
) {
const result = await this.viewColumnsService.columnUpdate({
viewId,
columnId,
column: body,
req
});
return result;
}

7
packages/nocodb/src/controllers/views.controller.ts

@ -48,6 +48,7 @@ export class ViewsController {
viewId,
view: body,
user: req.user,
req
});
return result;
}
@ -58,6 +59,7 @@ export class ViewsController {
const result = await this.viewsService.viewDelete({
viewId,
user: req.user,
req
});
return result;
}
@ -100,7 +102,7 @@ export class ViewsController {
@HttpCode(200)
@Acl('shareView')
async shareView(@Param('viewId') viewId: string, @Request() req) {
return await this.viewsService.shareView({ viewId, user: req.user });
return await this.viewsService.shareView({ viewId, user: req.user, req });
}
@Get([
@ -130,6 +132,7 @@ export class ViewsController {
viewId,
sharedView: body,
user: req.user,
req
});
}
@ -139,6 +142,6 @@ export class ViewsController {
])
@Acl('shareViewDelete')
async shareViewDelete(@Param('viewId') viewId: string, @Request() req) {
return await this.viewsService.shareViewDelete({ viewId, user: req.user });
return await this.viewsService.shareViewDelete({ viewId, user: req.user , req});
}
}

12
packages/nocodb/src/modules/jobs/jobs/at-import/at-import.processor.ts

@ -680,6 +680,7 @@ export class AtImportProcessor {
viewId: view.list[0].id,
view: { title: aTbl_grid.name },
user: syncDB.user,
req:{}
});
recordPerfStats(_perfStart, 'dbView.update');
@ -1526,6 +1527,7 @@ export class AtImportProcessor {
url: attachment.url,
size: attachment.size,
mimetype: attachment.type,
req:{}
})),
});
} catch (e) {
@ -1569,6 +1571,7 @@ export class AtImportProcessor {
ncCreatedProjectSchema = await this.basesService.baseCreate({
base: { title: projName },
user: { id: syncDB.user.id },
req:{}
});
recordPerfStats(_perfStart, 'base.create');
@ -1619,6 +1622,7 @@ export class AtImportProcessor {
title: viewName,
},
user: syncDB.user,
req:{}
});
recordPerfStats(_perfStart, 'dbView.galleryCreate');
@ -1685,6 +1689,7 @@ export class AtImportProcessor {
tableId: tblId,
body: formData,
user: syncDB.user,
req:{}
});
recordPerfStats(_perfStart, 'dbView.formCreate');
@ -1764,6 +1769,7 @@ export class AtImportProcessor {
grid: {
title: viewName,
},
req:{}
});
recordPerfStats(_perfStart, 'dbView.gridCreate');
@ -2140,6 +2146,7 @@ export class AtImportProcessor {
viewId: viewId,
filter: ncFilters[i],
user: syncDB.user,
req:{}
});
recordPerfStats(_perfStart, 'dbTableFilter.create');
@ -2218,6 +2225,7 @@ export class AtImportProcessor {
group_by_sort:
ncGroup[i].direction === 'ascending' ? 'asc' : 'desc',
},
req:{}
});
} catch (e) {
// ignore
@ -2239,6 +2247,7 @@ export class AtImportProcessor {
fk_column_id: columnId,
direction: s.sortSet[i].ascending ? 'asc' : 'desc',
},
req:{}
});
recordPerfStats(_perfStart, 'dbTableSort.create');
}
@ -2303,6 +2312,7 @@ export class AtImportProcessor {
show: false,
order: j + 1 + c.length,
},
req:{}
});
recordPerfStats(_perfStart, 'dbViewColumn.update');
}
@ -2330,6 +2340,7 @@ export class AtImportProcessor {
await this.formColumnsService.columnUpdate({
formViewColumnId: ncViewColumnId,
formViewColumn: formData,
req:{}
});
recordPerfStats(_perfStart, 'dbView.formColumnUpdate');
}
@ -2339,6 +2350,7 @@ export class AtImportProcessor {
viewId: viewId,
columnId: ncViewColumnId,
column: configData,
req:{}
});
recordPerfStats(_perfStart, 'dbViewColumn.update');
}

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

@ -901,6 +901,7 @@ export class ImportService {
fk_parent_id: getIdOrExternalId(fl.fk_parent_id),
}),
user: param.user,
req:{}
});
idMap.set(fl.id, fg.id);
@ -914,6 +915,7 @@ export class ImportService {
...sr,
fk_column_id: getIdOrExternalId(sr.fk_column_id),
}),
req:{}
});
}
@ -932,8 +934,9 @@ export class ImportService {
columnId: cl.id,
column: {
show: fcl.show,
order: fcl.order,
order: fcl.order
},
req:{}
});
}
@ -950,6 +953,7 @@ export class ImportService {
grid: {
...withoutNull(rest),
},
req:{}
});
}
break;
@ -965,6 +969,7 @@ export class ImportService {
formViewColumn: {
...withoutNull(rest),
},
req:{}
});
}
break;
@ -981,6 +986,7 @@ export class ImportService {
order: view.order,
},
user: param.user,
req:{}
});
}
}
@ -1008,6 +1014,7 @@ export class ImportService {
hook: {
...hookData,
},
req:{}
});
if (!hk) continue;
@ -1024,6 +1031,7 @@ export class ImportService {
fk_parent_id: getIdOrExternalId(fl.fk_parent_id),
}),
user: param.user,
req:{}
});
idMap.set(fl.id, fg.id);
@ -1051,6 +1059,7 @@ export class ImportService {
await this.gridsService.gridViewUpdate({
viewId: view.id,
grid: gridData,
req:{}
});
}
}
@ -1062,12 +1071,14 @@ export class ImportService {
const gview = await this.gridsService.gridViewCreate({
tableId: md.id,
grid: vw as ViewCreateReqType,
req:{}
});
const gridData = withoutNull(vw.view);
if (gridData) {
await this.gridsService.gridViewUpdate({
viewId: gview.id,
grid: gridData,
req:{}
});
}
return gview;
@ -1077,12 +1088,14 @@ export class ImportService {
tableId: md.id,
body: vw as ViewCreateReqType,
user,
req:{}
});
const formData = withoutNull(vw.view);
if (formData) {
await this.formsService.formViewUpdate({
formViewId: fview.id,
form: formData,
req:{}
});
}
return fview;
@ -1091,7 +1104,7 @@ export class ImportService {
const glview = await this.galleriesService.galleryViewCreate({
tableId: md.id,
gallery: vw as ViewCreateReqType,
user,
user,req:{}
});
const galleryData = withoutNull(vw.view);
if (galleryData) {
@ -1105,6 +1118,7 @@ export class ImportService {
await this.galleriesService.galleryViewUpdate({
galleryViewId: glview.id,
gallery: galleryData,
req:{}
});
}
return glview;
@ -1114,6 +1128,7 @@ export class ImportService {
tableId: md.id,
kanban: vw as ViewCreateReqType,
user,
req: {}
});
const kanbanData = withoutNull(vw.view);
if (kanbanData) {
@ -1159,6 +1174,7 @@ export class ImportService {
await this.kanbansService.kanbanViewUpdate({
kanbanViewId: kview.id,
kanban: kanbanData,
req: {}
});
}
return kview;

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

@ -14,7 +14,7 @@ export class ApiTokensService {
async apiTokenList(param: { userId: string }) {
return await ApiToken.list(param.userId);
}
async apiTokenCreate(param: { userId: string; tokenBody: ApiTokenReqType }) {
async apiTokenCreate(param: { userId: string; tokenBody: ApiTokenReqType; req:any }) {
validatePayload(
'swagger.json#/components/schemas/ApiTokenReq',
param.tokenBody,
@ -23,6 +23,7 @@ export class ApiTokensService {
this.appHooksService.emit(AppEvents.API_TOKEN_CREATE, {
userId: param.userId,
tokenBody: param.tokenBody,
req: param.req
});
return await ApiToken.insert({
@ -31,7 +32,7 @@ export class ApiTokensService {
});
}
async apiTokenDelete(param: { token; user: User }) {
async apiTokenDelete(param: { token; user: User; req:any }) {
const apiToken = await ApiToken.getByToken(param.token);
if (
!extractRolesObj(param.user.roles)[OrgUserRoles.SUPER_ADMIN] &&
@ -43,6 +44,7 @@ export class ApiTokensService {
this.appHooksService.emit(AppEvents.API_TOKEN_DELETE, {
userId: param.user?.id,
token: param.token,
req:param.req
});
// todo: verify token belongs to the user

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

@ -17,14 +17,19 @@ import type {
ViewType,
} from 'nocodb-sdk';
export interface ProjectInviteEvent {
export interface NcBaseEvent extends NcBaseEvent {
req: any;
clientId?: string;
}
export interface ProjectInviteEvent extends NcBaseEvent {
base: BaseType;
user: UserType;
invitedBy: UserType;
ip?: string;
}
export interface ProjectUserUpdateEvent {
export interface ProjectUserUpdateEvent extends NcBaseEvent {
base: BaseType;
user: UserType;
baseUser: ProjectUserReqType;
@ -32,7 +37,7 @@ export interface ProjectUserUpdateEvent {
ip?: string;
}
export interface ProjectUserResendInviteEvent {
export interface ProjectUserResendInviteEvent extends NcBaseEvent {
base: BaseType;
user: UserType;
baseUser: ProjectUserReqType;
@ -40,82 +45,82 @@ export interface ProjectUserResendInviteEvent {
ip?: string;
}
export interface ProjectCreateEvent {
export interface ProjectCreateEvent extends NcBaseEvent {
base: BaseType;
user: UserType;
xcdb: boolean;
}
export interface ProjectUpdateEvent {
export interface ProjectUpdateEvent extends NcBaseEvent {
base: BaseType;
user: UserType;
}
export interface ProjectDeleteEvent {
export interface ProjectDeleteEvent extends NcBaseEvent {
base: BaseType;
user: UserType;
}
export interface WelcomeEvent {
export interface WelcomeEvent extends NcBaseEvent {
user: UserType;
}
export interface UserSignupEvent {
export interface UserSignupEvent extends NcBaseEvent {
user: UserType;
ip?: string;
}
export interface UserSigninEvent {
export interface UserSigninEvent extends NcBaseEvent {
user: UserType;
ip?: string;
auditDescription?: string;
}
export interface ApiCreatedEvent {
export interface ApiCreatedEvent extends NcBaseEvent {
info: any;
}
export interface UserPasswordChangeEvent {
export interface UserPasswordChangeEvent extends NcBaseEvent {
user: UserType;
ip?: string;
}
export interface UserPasswordForgotEvent {
export interface UserPasswordForgotEvent extends NcBaseEvent {
user: UserType;
ip?: string;
}
export interface UserPasswordResetEvent {
export interface UserPasswordResetEvent extends NcBaseEvent {
user: UserType;
ip?: string;
}
export interface UserEmailVerificationEvent {
export interface UserEmailVerificationEvent extends NcBaseEvent {
user: UserType;
ip?: string;
}
export interface TableEvent {
export interface TableEvent extends NcBaseEvent {
table: TableType;
user: UserType;
ip?: string;
}
export interface ViewEvent {
export interface ViewEvent extends NcBaseEvent {
view: ViewType;
user?: UserType;
ip?: string;
showAs?: string;
}
export interface FilterEvent {
export interface FilterEvent extends NcBaseEvent {
filter: FilterType;
ip?: string;
hook?: HookType;
view?: ViewType;
}
export interface ColumnEvent {
export interface ColumnEvent extends NcBaseEvent {
table: TableType;
oldColumn?: ColumnType;
column: ColumnType;
@ -123,75 +128,75 @@ export interface ColumnEvent {
ip?: string;
}
export interface SortEvent {
export interface SortEvent extends NcBaseEvent {
sort: SortType;
ip?: string;
}
export interface OrgUserInviteEvent {
export interface OrgUserInviteEvent extends NcBaseEvent {
invitedBy: UserType;
user: UserType;
count?: number;
ip?: string;
}
export interface ViewColumnEvent {
export interface ViewColumnEvent extends NcBaseEvent {
// todo: type
viewColumn: any;
}
export interface RelationEvent {
export interface RelationEvent extends NcBaseEvent {
column: ColumnType;
}
export interface WebhookEvent {
export interface WebhookEvent extends NcBaseEvent {
hook: HookType;
}
export interface ApiTokenCreateEvent {
export interface ApiTokenCreateEvent extends NcBaseEvent {
userId: string;
tokenBody: ApiTokenReqType;
}
export interface ApiTokenDeleteEvent {
export interface ApiTokenDeleteEvent extends NcBaseEvent {
userId: string;
token: string;
}
export interface PluginTestEvent {
export interface PluginTestEvent extends NcBaseEvent {
testBody: PluginTestReqType;
}
export interface PluginEvent {
export interface PluginEvent extends NcBaseEvent {
plugin: PluginType;
}
export interface SharedBaseEvent {
export interface SharedBaseEvent extends NcBaseEvent {
link?: string;
base?: BaseType;
}
export interface BaseEvent {
export interface BaseEvent extends NcBaseEvent {
source: SourceType;
}
export interface AttachmentEvent {
export interface AttachmentEvent extends NcBaseEvent {
type: 'url' | 'file';
}
export interface FormColumnEvent {}
export interface FormColumnEvent extends NcBaseEvent {}
export interface GridColumnEvent {}
export interface GridColumnEvent extends NcBaseEvent {}
export interface MetaDiffEvent {
export interface MetaDiffEvent extends NcBaseEvent {
base: BaseType;
source?: SourceType;
}
export interface UIAclEvent {
export interface UIAclEvent extends NcBaseEvent {
base: BaseType;
}
export interface SyncSourceEvent {
export interface SyncSourceEvent extends NcBaseEvent {
syncSource: Partial<SyncSource>;
}

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

@ -15,7 +15,12 @@ import { utf8ify } from '~/helpers/stringHelpers';
export class AttachmentsService {
constructor(private readonly appHooksService: AppHooksService) {}
async upload(param: { path?: string; files: FileType[] }) {
async upload(param: {
path?: string;
// todo: proper type
files: unknown[];
req: any;
}) {
// TODO: add getAjvValidatorMw
const filePath = this.sanitizeUrlPath(
param.path?.toString()?.split('/') || [''],
@ -83,12 +88,22 @@ export class AttachmentsService {
this.appHooksService.emit(AppEvents.ATTACHMENT_UPLOAD, {
type: 'file',
req: param.req,
});
return attachments;
}
async uploadViaURL(param: { path?: string; urls: AttachmentReqType[] }) {
async uploadViaURL(param: {
path?: string;
urls: {
url: string;
fileName: string;
mimetype?: string;
size?: string | number;
}[];
req: any;
}) {
// TODO: add getAjvValidatorMw
const filePath = this.sanitizeUrlPath(
param?.path?.toString()?.split('/') || [''],
@ -133,6 +148,7 @@ export class AttachmentsService {
this.appHooksService.emit(AppEvents.ATTACHMENT_UPLOAD, {
type: 'url',
req: param.req,
});
return attachments;
}

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

@ -128,6 +128,7 @@ export class BaseUsersService {
user,
invitedBy: param.req.user,
ip: param.req.clientIp,
req: param.req,
});
const cachedUser = await NocoCache.get(
@ -165,6 +166,7 @@ export class BaseUsersService {
user,
invitedBy: param.req.user,
ip: param.req.clientIp,
req: param.req,
});
// in case of single user check for smtp failure
@ -271,6 +273,7 @@ export class BaseUsersService {
updatedBy: param.req.user,
ip: param.req.clientIp,
baseUser: param.baseUser,
req: param.req,
});
return {
@ -356,6 +359,7 @@ export class BaseUsersService {
invitedBy: param.req.user,
ip: param.req.clientIp,
baseUser: param.baseUser,
req: param.req,
});
return true;

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

@ -63,6 +63,7 @@ export class BasesService {
baseId: string;
base: ProjectUpdateReqType;
user: UserType;
req:any
}) {
validatePayload(
'swagger.json#/components/schemas/ProjectUpdateReq',
@ -84,6 +85,7 @@ export class BasesService {
this.appHooksService.emit(AppEvents.PROJECT_UPDATE, {
base,
user: param.user,
req: param.req,
});
return result;
@ -99,7 +101,7 @@ export class BasesService {
}
}
async baseSoftDelete(param: { baseId: any; user: UserType }) {
async baseSoftDelete(param: { baseId: any; user: UserType; req: any }) {
const base = await Base.getWithInfo(param.baseId);
if (!base) {
@ -111,12 +113,13 @@ export class BasesService {
this.appHooksService.emit(AppEvents.PROJECT_DELETE, {
base,
user: param.user,
req: param.req,
});
return true;
}
async baseCreate(param: { base: ProjectReqType; user: any }) {
async baseCreate(param: { base: ProjectReqType; user: any; req: any }) {
validatePayload('swagger.json#/components/schemas/ProjectReq', param.base);
const baseId = await this.metaService.genNanoid(MetaTable.PROJECT);
@ -205,6 +208,7 @@ export class BasesService {
this.appHooksService.emit(AppEvents.APIS_CREATED, {
info,
req: param.req,
});
delete source.config;
@ -215,18 +219,20 @@ export class BasesService {
base,
user: param.user,
xcdb: !baseBody.external,
req: param.req,
});
return base;
}
async createDefaultBase(param: { user: UserType }) {
async createDefaultBase(param: { user: UserType; req: any }) {
const base = await this.baseCreate({
base: {
title: 'Getting Started',
type: 'database',
} as any,
user: param.user,
req: param.req,
});
const sqlUI = SqlUiFactory.create({ client: base.sources[0].type });

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

@ -1014,6 +1014,7 @@ export class ColumnsService {
column,
user: param.req?.user,
ip: param.req?.clientIp,
req: param.req,
});
return table;
@ -1150,6 +1151,7 @@ export class ColumnsService {
base_id: base.id,
source_id: source.id,
},
req: param.req,
});
break;
@ -1410,6 +1412,7 @@ export class ColumnsService {
},
user: param.req?.user,
ip: param.req?.clientIp,
req: param.req,
});
return table;
@ -1590,6 +1593,7 @@ export class ColumnsService {
}
this.appHooksService.emit(AppEvents.RELATION_DELETE, {
column,
req: param.req,
});
break;
case UITypes.ForeignKey: {
@ -1651,6 +1655,7 @@ export class ColumnsService {
column,
user: param.req?.user,
ip: param.req?.clientIp,
req: param.req,
});
return table;

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

@ -14,6 +14,7 @@ export class FiltersService {
filter: FilterReqType;
hookId: any;
user: UserType;
req: any;
}) {
validatePayload('swagger.json#/components/schemas/FilterReq', param.filter);
@ -31,6 +32,7 @@ export class FiltersService {
this.appHooksService.emit(AppEvents.FILTER_CREATE, {
filter,
hook,
req: param.req,
});
return filter;
}
@ -39,7 +41,7 @@ export class FiltersService {
return Filter.rootFilterListByHook({ hookId: param.hookId });
}
async filterDelete(param: { filterId: string }) {
async filterDelete(param: { filterId: string; req: any }) {
const filter = await Filter.get(param.filterId);
if (!filter) {
@ -50,6 +52,7 @@ export class FiltersService {
this.appHooksService.emit(AppEvents.FILTER_DELETE, {
filter,
req: param.req,
});
return true;
@ -59,6 +62,7 @@ export class FiltersService {
filter: FilterReqType;
viewId: string;
user: UserType;
req: any;
}) {
validatePayload('swagger.json#/components/schemas/FilterReq', param.filter);
@ -72,6 +76,7 @@ export class FiltersService {
this.appHooksService.emit(AppEvents.FILTER_CREATE, {
filter,
view,
req: param.req,
});
return filter;
@ -81,6 +86,7 @@ export class FiltersService {
filter: FilterReqType;
filterId: string;
user: UserType;
req: any;
}) {
validatePayload('swagger.json#/components/schemas/FilterReq', param.filter);
@ -94,6 +100,7 @@ export class FiltersService {
this.appHooksService.emit(AppEvents.FILTER_UPDATE, {
filter,
req: param.req,
});
return res;

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

@ -12,6 +12,7 @@ export class FormColumnsService {
formViewColumnId: string;
// todo: replace with FormColumnReq
formViewColumn: FormViewColumn;
req: any;
}) {
validatePayload(
'swagger.json#/components/schemas/FormColumnReq',
@ -23,7 +24,9 @@ export class FormColumnsService {
param.formViewColumn,
);
this.appHooksService.emit(AppEvents.FORM_COLUMN_UPDATE, {});
this.appHooksService.emit(AppEvents.FORM_COLUMN_UPDATE, {
req: param.req,
});
return res;
}

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

@ -23,6 +23,7 @@ export class FormsService {
tableId: string;
body: ViewCreateReqType;
user: UserType;
req: any;
}) {
validatePayload(
'swagger.json#/components/schemas/ViewCreateReq',
@ -39,17 +40,19 @@ export class FormsService {
this.appHooksService.emit(AppEvents.VIEW_CREATE, {
view,
showAs: 'form',
req: param.req,
});
this.appHooksService.emit(AppEvents.VIEW_CREATE, {
user: param.user,
view,
req: param.req,
});
return view;
}
async formViewUpdate(param: { formViewId: string; form: FormUpdateReqType }) {
async formViewUpdate(param: { formViewId: string; form: FormUpdateReqType; req: any }) {
validatePayload(
'swagger.json#/components/schemas/FormUpdateReq',
param.form,
@ -65,6 +68,7 @@ export class FormsService {
this.appHooksService.emit(AppEvents.VIEW_UPDATE, {
view,
showAs: 'form',
req: param.req
});
return res;

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

@ -22,6 +22,8 @@ export class GalleriesService {
tableId: string;
gallery: ViewCreateReqType;
user: UserType;
req: any;
}) {
validatePayload(
'swagger.json#/components/schemas/ViewCreateReq',
@ -38,6 +40,7 @@ export class GalleriesService {
this.appHooksService.emit(AppEvents.VIEW_CREATE, {
view,
showAs: 'gallery',
req: param.req,
});
return view;
}
@ -45,6 +48,7 @@ export class GalleriesService {
async galleryViewUpdate(param: {
galleryViewId: string;
gallery: GalleryUpdateReqType;
req: any;
}) {
validatePayload(
'swagger.json#/components/schemas/GalleryUpdateReq',
@ -62,6 +66,7 @@ export class GalleriesService {
this.appHooksService.emit(AppEvents.VIEW_UPDATE, {
view,
showAs: 'gallery',
req: param.req,
});
return res;

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

@ -16,6 +16,7 @@ export class GridColumnsService {
async gridColumnUpdate(param: {
gridViewColumnId: string;
grid: GridColumnReqType;
req: any;
}) {
validatePayload(
'swagger.json#/components/schemas/GridColumnReq',
@ -24,7 +25,9 @@ export class GridColumnsService {
const res = await GridViewColumn.update(param.gridViewColumnId, param.grid);
this.appHooksService.emit(AppEvents.GRID_COLUMN_UPDATE, {});
this.appHooksService.emit(AppEvents.GRID_COLUMN_UPDATE, {
req: param.req
});
return res;
}

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

@ -10,7 +10,7 @@ import { GridView, View } from '~/models';
export class GridsService {
constructor(private readonly appHooksService: AppHooksService) {}
async gridViewCreate(param: { tableId: string; grid: ViewCreateReqType }) {
async gridViewCreate(param: { tableId: string; grid: ViewCreateReqType; req:any}) {
validatePayload(
'swagger.json#/components/schemas/ViewCreateReq',
param.grid,
@ -26,16 +26,13 @@ export class GridsService {
this.appHooksService.emit(AppEvents.VIEW_CREATE, {
view,
showAs: 'grid',
});
this.appHooksService.emit(AppEvents.VIEW_CREATE, {
view,
req: param.req,
});
return view;
}
async gridViewUpdate(param: { viewId: string; grid: GridUpdateReqType }) {
async gridViewUpdate(param: { viewId: string; grid: GridUpdateReqType; req: any }) {
validatePayload(
'swagger.json#/components/schemas/GridUpdateReq',
param.grid,
@ -52,6 +49,7 @@ export class GridsService {
this.appHooksService.emit(AppEvents.VIEW_UPDATE, {
view,
showAs: 'map',
req: param.req,
});
return res;

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

@ -37,7 +37,9 @@ export class HooksService {
return await HookLog.list({ fk_hook_id: param.hookId }, param.query);
}
async hookCreate(param: { tableId: string; hook: HookReqType }) {
async hookCreate(param: { tableId: string; hook: HookReqType;
req: any
}) {
validatePayload('swagger.json#/components/schemas/HookReq', param.hook);
this.validateHookPayload(param.hook.notification);
@ -49,12 +51,15 @@ export class HooksService {
this.appHooksService.emit(AppEvents.WEBHOOK_CREATE, {
hook,
req: param.req,
});
return hook;
}
async hookDelete(param: { hookId: string }) {
async hookDelete(param: { hookId: string
req: any
}) {
const hook = await Hook.get(param.hookId);
if (!hook) {
@ -64,11 +69,12 @@ export class HooksService {
await Hook.delete(param.hookId);
this.appHooksService.emit(AppEvents.WEBHOOK_DELETE, {
hook,
req: param.req,
});
return true;
}
async hookUpdate(param: { hookId: string; hook: HookReqType }) {
async hookUpdate(param: { hookId: string; hook: HookReqType ; req:any}) {
validatePayload('swagger.json#/components/schemas/HookReq', param.hook);
const hook = await Hook.get(param.hookId);
@ -86,12 +92,13 @@ export class HooksService {
...hook,
...param.hook,
},
req: param.req,
});
return res;
}
async hookTest(param: { tableId: string; hookTest: HookTestReqType }) {
async hookTest(param: { tableId: string; hookTest: HookTestReqType; req: any }) {
validatePayload(
'swagger.json#/components/schemas/HookTestReq',
param.hookTest,
@ -122,6 +129,7 @@ export class HooksService {
} finally {
this.appHooksService.emit(AppEvents.WEBHOOK_TEST, {
hook,
req: param.req,
});
}

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

@ -22,6 +22,7 @@ export class KanbansService {
tableId: string;
kanban: ViewCreateReqType;
user: UserType;
req: any;
}) {
validatePayload(
'swagger.json#/components/schemas/ViewCreateReq',
@ -39,6 +40,8 @@ export class KanbansService {
view,
showAs: 'kanban',
user: param.user,
req: param.req
});
return view;
@ -47,6 +50,7 @@ export class KanbansService {
async kanbanViewUpdate(param: {
kanbanViewId: string;
kanban: KanbanUpdateReqType;
req: any;
}) {
validatePayload(
'swagger.json#/components/schemas/KanbanUpdateReq',
@ -64,6 +68,7 @@ export class KanbansService {
this.appHooksService.emit(AppEvents.VIEW_UPDATE, {
view,
showAs: 'kanban',
req: param.req
});
return res;

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

@ -18,6 +18,7 @@ export class MapsService {
tableId: string;
map: ViewCreateReqType;
user: UserType;
req: any;
}) {
validatePayload(
'swagger.json#/components/schemas/ViewCreateReq',
@ -33,12 +34,16 @@ export class MapsService {
this.appHooksService.emit(AppEvents.VIEW_CREATE, {
view,
showAs: 'map',
req: param.req
});
return view;
}
async mapViewUpdate(param: { mapViewId: string; map: MapUpdateReqType }) {
async mapViewUpdate(param: { mapViewId: string; map: MapUpdateReqType;
req: any;
}) {
validatePayload('swagger.json#/components/schemas/MapUpdateReq', param.map);
const view = await View.get(param.mapViewId);
@ -52,6 +57,7 @@ export class MapsService {
this.appHooksService.emit(AppEvents.VIEW_UPDATE, {
view,
showAs: 'map',
req: param.req,
});
return res;

6
packages/nocodb/src/services/meta-diffs.service.ts

@ -882,7 +882,7 @@ export class MetaDiffsService {
await this.extractAndGenerateManyToManyRelations(await source.getModels());
}
async metaDiffSync(param: { baseId: string }) {
async metaDiffSync(param: { baseId: string; req: any }) {
const base = await Base.getWithInfo(param.baseId);
for (const source of base.sources) {
await this.syncBaseMeta(base, source);
@ -890,12 +890,13 @@ export class MetaDiffsService {
this.appHooksService.emit(AppEvents.META_DIFF_SYNC, {
base,
req: param.req,
});
return true;
}
async baseMetaDiffSync(param: { baseId: string; sourceId: string }) {
async baseMetaDiffSync(param: { baseId: string; sourceId: string, req: any }) {
const base = await Base.getWithInfo(param.baseId);
const source = await Source.get(param.sourceId);
@ -904,6 +905,7 @@ export class MetaDiffsService {
this.appHooksService.emit(AppEvents.META_DIFF_SYNC, {
base,
source,
req: param.req,
});
return true;

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

@ -13,6 +13,7 @@ export class ModelVisibilitiesService {
async xcVisibilityMetaSetAll(param: {
visibilityRule: VisibilityRuleReqType;
baseId: string;
req: any;
}) {
validatePayload(
'swagger.json#/components/schemas/VisibilityRuleReq',
@ -58,6 +59,7 @@ export class ModelVisibilitiesService {
}
this.appHooksService.emit(AppEvents.UI_ACL_UPDATE, {
base,
req: param.req,
});
return true;

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

@ -15,8 +15,11 @@ import { Notification } from '~/models';
export class NotificationsService implements OnModuleInit, OnModuleDestroy {
constructor(protected readonly appHooks: AppHooksService) {}
protected async insertNotification(insertData: Partial<Notification>) {
this.appHooks.emit('notification' as any, insertData);
protected async insertNotification(
insertData: Partial<Notification>,
req: any,
) {
this.appHooks.emit('notification' as any, { ...insertData, req } as any);
await Notification.insert(insertData);
}
@ -28,6 +31,7 @@ export class NotificationsService implements OnModuleInit, OnModuleDestroy {
event: AppEvents;
data: any;
}) {
const { req } = data;
switch (event) {
case AppEvents.PROJECT_INVITE:
{
@ -41,19 +45,20 @@ export class NotificationsService implements OnModuleInit, OnModuleDestroy {
title: base.title,
type: base.type,
invited_by: invitedBy.email,
},
});
}
},
req,);
}
break;
case AppEvents.WELCOME:
{
const { user } = data as WelcomeEvent;
const { user, req } = data as WelcomeEvent;
await this.insertNotification({
fk_user_id: user.id,
type: AppEvents.WELCOME,
body: {},
});
}, req);
}
break;
}

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

@ -35,7 +35,9 @@ export class OrgTokensService {
);
}
async apiTokenCreate(param: { user: User; apiToken: ApiTokenReqType }) {
async apiTokenCreate(param: { user: User; apiToken: ApiTokenReqType
req: any;
}) {
validatePayload(
'swagger.json#/components/schemas/ApiTokenReq',
param.apiToken,
@ -49,12 +51,16 @@ export class OrgTokensService {
this.appHooksService.emit(AppEvents.ORG_API_TOKEN_CREATE, {
tokenBody: param.apiToken,
userId: param.user?.id,
req: param.req
});
return apiToken;
}
async apiTokenDelete(param: { user: User; token: string }) {
async apiTokenDelete(param: { user: User; token: string;
req: any;
}) {
const fk_user_id = param.user.id;
const apiToken = await ApiToken.getByToken(param.token);
if (
@ -68,6 +74,7 @@ export class OrgTokensService {
this.appHooksService.emit(AppEvents.ORG_API_TOKEN_DELETE, {
token: param.token,
userId: param.user?.id,
req: param['req'],
});
return res;

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

@ -148,6 +148,7 @@ export class OrgUsersService {
user,
count,
ip: param.req.clientIp,
req: param.req,
});
// in case of single user check for smtp failure
@ -232,6 +233,7 @@ export class OrgUsersService {
invitedBy: param.req.user,
user,
ip: param.req.clientIp,
req: param.req,
});
return true;

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

@ -14,7 +14,7 @@ export class PluginsService {
return await Plugin.list();
}
async pluginTest(param: { body: PluginTestReqType }) {
async pluginTest(param: { body: PluginTestReqType; req: any}) {
validatePayload(
'swagger.json#/components/schemas/PluginTestReq',
param.body,
@ -22,6 +22,7 @@ export class PluginsService {
this.appHooksService.emit(AppEvents.PLUGIN_TEST, {
testBody: param.body,
req: param.req
});
return await NcPluginMgrv2.test(param.body);
}
@ -29,7 +30,7 @@ export class PluginsService {
async pluginRead(param: { pluginId: string }) {
return await Plugin.get(param.pluginId);
}
async pluginUpdate(param: { pluginId: string; plugin: PluginType }) {
async pluginUpdate(param: { pluginId: string; plugin: PluginType; req: any }) {
validatePayload('swagger.json#/components/schemas/PluginReq', param.plugin);
const plugin = await Plugin.update(param.pluginId, param.plugin);
@ -38,6 +39,7 @@ export class PluginsService {
plugin.active ? AppEvents.PLUGIN_INSTALL : AppEvents.PLUGIN_UNINSTALL,
{
plugin,
req: param.req
},
);

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

@ -25,6 +25,8 @@ export class SharedBasesService {
roles: string;
password: string;
siteUrl: string;
req: any
}): Promise<any> {
validatePayload('swagger.json#/components/schemas/SharedBaseReq', param);
@ -61,6 +63,7 @@ export class SharedBasesService {
this.appHooksService.emit(AppEvents.SHARED_BASE_GENERATE_LINK, {
link: data.url,
base,
req: param.req,
});
return data;
@ -71,6 +74,7 @@ export class SharedBasesService {
roles: string;
password: string;
siteUrl: string;
req:any
}): Promise<any> {
validatePayload('swagger.json#/components/schemas/SharedBaseReq', param);
@ -106,6 +110,7 @@ export class SharedBasesService {
this.appHooksService.emit(AppEvents.SHARED_BASE_GENERATE_LINK, {
link: data.url,
base,
req: param.req
});
return data;
}
@ -125,7 +130,9 @@ export class SharedBasesService {
return `${siteUrl}${config.dashboardPath}#/base/${base.uuid}`;
}
async disableSharedBaseLink(param: { baseId: string }): Promise<any> {
async disableSharedBaseLink(param: { baseId: string
req:any
}): Promise<any> {
const base = await Base.get(param.baseId);
if (!base) {
@ -139,6 +146,7 @@ export class SharedBasesService {
this.appHooksService.emit(AppEvents.SHARED_BASE_DELETE_LINK, {
base,
req: param.req,
});
return { uuid: null };
}

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

@ -14,7 +14,9 @@ export class SortsService {
return Sort.get(param.sortId);
}
async sortDelete(param: { sortId: string }) {
async sortDelete(param: { sortId: string
req: any
}) {
const sort = await Sort.get(param.sortId);
if (!sort) {
@ -25,11 +27,14 @@ export class SortsService {
this.appHooksService.emit(AppEvents.SORT_CREATE, {
sort,
req: param.req
});
return true;
}
async sortUpdate(param: { sortId: any; sort: SortReqType }) {
async sortUpdate(param: { sortId: any; sort: SortReqType
req: any
}) {
validatePayload('swagger.json#/components/schemas/SortReq', param.sort);
const sort = await Sort.get(param.sortId);
@ -42,12 +47,16 @@ export class SortsService {
this.appHooksService.emit(AppEvents.SORT_UPDATE, {
sort,
req: param.req
});
return res;
}
async sortCreate(param: { viewId: any; sort: SortReqType }) {
async sortCreate(param: { viewId: any; sort: SortReqType
req: any
}) {
validatePayload('swagger.json#/components/schemas/SortReq', param.sort);
const sort = await Sort.insert({
@ -57,6 +66,7 @@ export class SortsService {
this.appHooksService.emit(AppEvents.SORT_CREATE, {
sort,
req: param.req,
});
return sort;

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

@ -24,6 +24,7 @@ export class SourcesService {
sourceId: string;
source: BaseReqType;
baseId: string;
req: any;
}) {
validatePayload('swagger.json#/components/schemas/BaseReq', param.source);
@ -40,6 +41,7 @@ export class SourcesService {
this.appHooksService.emit(AppEvents.BASE_UPDATE, {
source,
req: param.req,
});
return source;
@ -51,12 +53,13 @@ export class SourcesService {
return sources;
}
async baseDelete(param: { sourceId: string }) {
async baseDelete(param: { sourceId: string; req:any}) {
try {
const source = await Source.get(param.sourceId, true);
await source.delete();
this.appHooksService.emit(AppEvents.BASE_DELETE, {
source,
req: param.req,
});
} catch (e) {
NcError.badRequest(e);
@ -78,6 +81,7 @@ export class SourcesService {
baseId: string;
source: BaseReqType;
logger?: (message: string) => void;
req: any;
}) {
validatePayload('swagger.json#/components/schemas/BaseReq', param.source);
@ -103,12 +107,14 @@ export class SourcesService {
this.appHooksService.emit(AppEvents.APIS_CREATED, {
info,
req: param.req,
});
delete source.config;
this.appHooksService.emit(AppEvents.BASE_CREATE, {
source,
req: param.req,
});
return source;

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

@ -20,6 +20,7 @@ export class SyncService {
sourceId?: string;
userId: string;
syncPayload: Partial<SyncSource>;
req: any;
}) {
const base = await Base.getWithInfo(param.baseId);
@ -32,12 +33,15 @@ export class SyncService {
this.appHooksService.emit(AppEvents.SYNC_SOURCE_CREATE, {
syncSource: sync,
req: param.req
});
return sync;
}
async syncDelete(param: { syncId: string }) {
async syncDelete(param: { syncId: string
req: any
}) {
const syncSource = await SyncSource.get(param.syncId);
if (!syncSource) {
@ -48,6 +52,7 @@ export class SyncService {
this.appHooksService.emit(AppEvents.SYNC_SOURCE_DELETE, {
syncSource,
req: param.req
});
return res;
}
@ -55,6 +60,7 @@ export class SyncService {
async syncUpdate(param: {
syncId: string;
syncPayload: Partial<SyncSource>;
req: any;
}) {
const syncSource = await SyncSource.get(param.syncId);
@ -66,6 +72,8 @@ export class SyncService {
this.appHooksService.emit(AppEvents.SYNC_SOURCE_UPDATE, {
syncSource,
req: param.req
});
return res;

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

@ -43,6 +43,7 @@ export class TablesService {
table: TableReqType & { base_id?: string };
baseId?: string;
user: UserType;
req: any;
}) {
const model = await Model.get(param.tableId);
@ -145,6 +146,7 @@ export class TablesService {
this.appHooksService.emit(AppEvents.TABLE_UPDATE, {
table: model,
user: param.user,
req: param.req,
});
return true;
@ -225,6 +227,7 @@ export class TablesService {
table,
user: param.user,
ip: param.req?.clientIp,
req: param.req,
});
result = await table.delete(ncMeta);
@ -528,6 +531,7 @@ export class TablesService {
table: result,
user: param.user,
ip: param.req?.clientIp,
req: param.req,
});
return result;

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

@ -91,11 +91,13 @@ export class UsersService {
salt,
password,
email_verification_token,
req
}: {
email: string;
salt: any;
password;
email_verification_token;
req: any;
}) {
this.validateEmailPattern(email);
@ -137,7 +139,7 @@ export class UsersService {
// if first user and super admin, create a base
if (isFirstUser && process.env.NC_CLOUD !== 'true') {
// todo: update swagger type
(user as any).createdProject = await this.createDefaultProject(user);
(user as any).createdProject = await this.createDefaultProject(user, req);
}
// todo: update swagger type
@ -191,6 +193,7 @@ export class UsersService {
this.appHooksService.emit(AppEvents.USER_PASSWORD_CHANGE, {
user: user,
ip: param.req?.clientIp,
req: param.req,
});
return true;
@ -247,6 +250,7 @@ export class UsersService {
this.appHooksService.emit(AppEvents.USER_PASSWORD_FORGOT, {
user: user,
ip: param.req?.clientIp,
req: param.req,
});
} else {
return NcError.badRequest('Your email has not been registered.');
@ -319,6 +323,7 @@ export class UsersService {
this.appHooksService.emit(AppEvents.USER_PASSWORD_RESET, {
user: user,
ip: param.req?.clientIp,
req: param.req,
});
return true;
@ -348,6 +353,7 @@ export class UsersService {
this.appHooksService.emit(AppEvents.USER_EMAIL_VERIFICATION, {
user: user,
ip: req?.clientIp,
req
});
return true;
@ -459,6 +465,7 @@ export class UsersService {
salt,
password,
email_verification_token,
req: param.req,
});
createdProject = _createdProject;
}
@ -497,18 +504,21 @@ export class UsersService {
this.appHooksService.emit(AppEvents.USER_SIGNUP, {
user: user,
ip: param.req?.clientIp,
req: param.req,
});
this.appHooksService.emit(AppEvents.WELCOME, {
user,
req: param.req,
});
return { ...(await this.login(user)), createdProject };
return { ...(await this.login(user, param.req)), createdProject };
}
async login(user: UserType & { provider?: string }) {
async login(user: UserType & { provider?: string }, req: any) {
this.appHooksService.emit(AppEvents.USER_SIGNIN, {
user,
req,
});
return {
token: genJwt(user, Noco.getConfig()),
@ -535,10 +545,11 @@ export class UsersService {
param.res.clearCookie('refresh_token');
}
private async createDefaultProject(user: User) {
private async createDefaultProject(user: User,req:any) {
// create new base for user
const base = await this.basesService.createDefaultBase({
user,
req
});
return base;

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

@ -12,7 +12,9 @@ export class ViewColumnsService {
async columnList(param: { viewId: string }) {
return await View.getColumns(param.viewId, undefined);
}
async columnAdd(param: { viewId: string; column: ViewColumnReqType }) {
async columnAdd(param: { viewId: string; column: ViewColumnReqType
req: any
}) {
validatePayload(
'swagger.json#/components/schemas/ViewColumnReq',
param.column,
@ -28,6 +30,7 @@ export class ViewColumnsService {
);
this.appHooksService.emit(AppEvents.VIEW_COLUMN_CREATE, {
viewColumn,
req:param.req
});
return viewColumn;
@ -37,6 +40,7 @@ export class ViewColumnsService {
viewId: string;
columnId: string;
column: ViewColumnUpdateReqType;
req: any
}) {
validatePayload(
'swagger.json#/components/schemas/ViewColumnUpdateReq',
@ -51,6 +55,7 @@ export class ViewColumnsService {
this.appHooksService.emit(AppEvents.VIEW_COLUMN_UPDATE, {
viewColumn: param.column,
req: param.req
});
return result;

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

@ -91,7 +91,9 @@ export class ViewsService {
return filteredViewList;
}
async shareView(param: { viewId: string; user: UserType }) {
async shareView(param: { viewId: string; user: UserType
req: any;
}) {
const res = await View.share(param.viewId);
const view = await View.get(param.viewId);
@ -103,6 +105,7 @@ export class ViewsService {
this.appHooksService.emit(AppEvents.SHARED_VIEW_CREATE, {
user: param.user,
view,
req: param.req
});
return res;
@ -112,6 +115,7 @@ export class ViewsService {
viewId: string;
view: ViewUpdateReqType;
user: UserType;
req: any;
}) {
validatePayload(
'swagger.json#/components/schemas/ViewUpdateReq',
@ -132,11 +136,15 @@ export class ViewsService {
...param.view,
},
user: param.user,
req: param.req
});
return result;
}
async viewDelete(param: { viewId: string; user: UserType }) {
async viewDelete(param: { viewId: string; user: UserType
req: any;
}) {
const view = await View.get(param.viewId);
if (!view) {
@ -148,6 +156,7 @@ export class ViewsService {
this.appHooksService.emit(AppEvents.VIEW_DELETE, {
view,
user: param.user,
req: param.req,
});
return true;
@ -157,6 +166,7 @@ export class ViewsService {
viewId: string;
sharedView: SharedViewReqType;
user: UserType;
req: any;
}) {
validatePayload(
'swagger.json#/components/schemas/SharedViewReq',
@ -174,12 +184,13 @@ export class ViewsService {
this.appHooksService.emit(AppEvents.SHARED_VIEW_UPDATE, {
user: param.user,
view,
req: param.req
});
return result;
}
async shareViewDelete(param: { viewId: string; user: UserType }) {
async shareViewDelete(param: { viewId: string; user: UserType; req: any }) {
const view = await View.get(param.viewId);
if (!view) {
@ -190,6 +201,7 @@ export class ViewsService {
this.appHooksService.emit(AppEvents.SHARED_VIEW_DELETE, {
user: param.user,
view,
req: param.req
});
return true;

Loading…
Cancel
Save