Browse Source

chore: sync with nocodb package

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5444/head
Pranav C 1 year ago
parent
commit
ab7f204fd2
  1. 6
      packages/nocodb-nest/src/models/Audit.ts
  2. 6
      packages/nocodb-nest/src/modules/columns/columns.service.ts
  3. 2
      packages/nocodb-nest/src/modules/hooks/hooks.controller.ts
  4. 4
      packages/nocodb-nest/src/modules/org-users/org-users.service.ts
  5. 18
      packages/nocodb-nest/src/modules/project-users/project-users.service.ts
  6. 16
      packages/nocodb-nest/src/modules/public-datas/public-datas.service.ts
  7. 7
      packages/nocodb-nest/src/modules/tables/tables.service.ts
  8. 19
      packages/nocodb-nest/src/modules/users/users.controller.ts
  9. 37
      packages/nocodb-nest/src/modules/users/users.service.ts
  10. 124789
      packages/nocodb-nest/src/schema/swagger.json

6
packages/nocodb-nest/src/models/Audit.ts

@ -30,13 +30,11 @@ const opSubTypes = <const>[
'LINK_RECORD',
'UNLINK_RECORD',
'DELETE',
'CREATED',
'DELETED',
'RENAMED',
'CREATE',
'RENAME',
'IMPORT_FROM_ZIP',
'EXPORT_TO_FS',
'EXPORT_TO_ZIP',
'UPDATED',
'SIGNIN',
'SIGNUP',
'PASSWORD_RESET',

6
packages/nocodb-nest/src/modules/columns/columns.service.ts

@ -829,7 +829,7 @@ export class ColumnsService {
await Audit.insert({
project_id: base.project_id,
op_type: AuditOperationTypes.TABLE_COLUMN,
op_sub_type: AuditOperationSubTypes.UPDATED,
op_sub_type: AuditOperationSubTypes.UPDATE,
user: param.req?.user?.email,
description: `updated column ${column.column_name} with alias ${column.title} from table ${table.table_name}`,
ip: param.req?.clientIp,
@ -1131,7 +1131,7 @@ export class ColumnsService {
await Audit.insert({
project_id: base.project_id,
op_type: AuditOperationTypes.TABLE_COLUMN,
op_sub_type: AuditOperationSubTypes.CREATED,
op_sub_type: AuditOperationSubTypes.CREATE,
user: param?.req.user?.email,
description: `created column ${colBody.column_name} with alias ${colBody.title} from table ${table.table_name}`,
ip: param?.req.clientIp,
@ -1342,7 +1342,7 @@ export class ColumnsService {
await Audit.insert({
project_id: base.project_id,
op_type: AuditOperationTypes.TABLE_COLUMN,
op_sub_type: AuditOperationSubTypes.DELETED,
op_sub_type: AuditOperationSubTypes.DELETE,
user: param?.req?.user?.email,
description: `deleted column ${column.column_name} with alias ${column.title} from table ${table.table_name}`,
ip: param?.req.clientIp,

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

@ -87,7 +87,7 @@ export class HooksController {
async tableSampleData(
@Param('tableId') tableId: string,
@Param('operation') operation: HookType['operation'],
@Param('version') version: any, //HookType['version'],
@Param('version') version: HookType['version'],
) {
return await this.hooksService.tableSampleData({
tableId,

4
packages/nocodb-nest/src/modules/org-users/org-users.service.ts

@ -154,7 +154,7 @@ export class OrgUsersService {
op_type: AuditOperationTypes.ORG_USER,
op_sub_type: AuditOperationSubTypes.INVITE,
user: param.req.user.email,
description: `invited ${email} to ${param.projectId} project `,
description: `${email} has been invited to ${param.projectId} project`,
ip: param.req.clientIp,
});
// in case of single user check for smtp failure
@ -239,7 +239,7 @@ export class OrgUsersService {
op_type: AuditOperationTypes.ORG_USER,
op_sub_type: AuditOperationSubTypes.RESEND_INVITE,
user: user.email,
description: `resent a invite to ${user.email} `,
description: `${user.email} has been re-invited`,
ip: param.req.clientIp,
});

18
packages/nocodb-nest/src/modules/project-users/project-users.service.ts

@ -1,5 +1,5 @@
import { Injectable } from '@nestjs/common';
import { OrgUserRoles, PluginCategory } from 'nocodb-sdk';
import { AuditOperationSubTypes, AuditOperationTypes, OrgUserRoles, PluginCategory } from 'nocodb-sdk'
import { T } from 'nc-help';
import { v4 as uuidv4 } from 'uuid';
import * as ejs from 'ejs';
@ -92,8 +92,8 @@ export class ProjectUsersService {
await Audit.insert({
project_id: param.projectId,
op_type: 'AUTHENTICATION',
op_sub_type: 'INVITE',
op_type: AuditOperationTypes.AUTHENTICATION,
op_sub_type: AuditOperationSubTypes.INVITE,
user: param.req.user.email,
description: `invited ${email} to ${param.projectId} project `,
ip: param.req.clientIp,
@ -121,8 +121,8 @@ export class ProjectUsersService {
await Audit.insert({
project_id: param.projectId,
op_type: 'AUTHENTICATION',
op_sub_type: 'INVITE',
op_type: AuditOperationTypes.AUTHENTICATION,
op_sub_type: AuditOperationSubTypes.INVITE,
user: param.req.user.email,
description: `invited ${email} to ${param.projectId} project `,
ip: param.req.clientIp,
@ -203,8 +203,8 @@ export class ProjectUsersService {
);
await Audit.insert({
op_type: 'AUTHENTICATION',
op_sub_type: 'ROLES_MANAGEMENT',
op_type: AuditOperationTypes.AUTHENTICATION,
op_sub_type: AuditOperationSubTypes.ROLES_MANAGEMENT,
user: param.req.user.email,
description: `updated roles for ${user.email} with ${param.projectUser.roles} `,
ip: param.req.clientIp,
@ -282,8 +282,8 @@ export class ProjectUsersService {
await this.sendInviteEmail(user.email, invite_token, param.req);
await Audit.insert({
op_type: 'AUTHENTICATION',
op_sub_type: 'RESEND_INVITE',
op_type: AuditOperationTypes.AUTHENTICATION,
op_sub_type: AuditOperationSubTypes.RESEND_INVITE ,
user: user.email,
description: `resent a invite to ${user.email} `,
ip: param.req.clientIp,

16
packages/nocodb-nest/src/modules/public-datas/public-datas.service.ts

@ -253,7 +253,7 @@ export class PublicDatasService {
const fieldName = file?.fieldname?.replace(/^_|\[\d*]$/g, '');
const filePath = sanitizeUrlPath([
'v1',
'noco',
project.title,
model.title,
fieldName,
@ -264,18 +264,24 @@ export class PublicDatasService {
fields[fieldName].uidt === UITypes.Attachment
) {
attachments[fieldName] = attachments[fieldName] || [];
const fileName = `${nanoid(6)}_${file.originalname}`;
let url = await storageAdapter.fileCreate(
const fileName = `${nanoid(18)}${path.extname(file.originalname)}`;
const url = await storageAdapter.fileCreate(
slash(path.join('nc', 'uploads', ...filePath, fileName)),
file,
);
let attachmentPath;
// if `url` is null, then it is local attachment
if (!url) {
url = `${param.siteUrl}/download/${filePath.join('/')}/${fileName}`;
// then store the attachment path only
// url will be constructed in `useAttachmentCell`
attachmentPath = `download/${filePath.join('/')}/${fileName}`;
}
attachments[fieldName].push({
url,
...(url ? { url } : {}),
...(attachmentPath ? { path: attachmentPath } : {}),
title: file.originalname,
mimetype: file.mimetype,
size: file.size,

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

@ -1,3 +1,4 @@
import { Injectable } from '@nestjs/common';
import DOMPurify from 'isomorphic-dompurify';
import {
@ -192,7 +193,7 @@ export class TablesService {
project_id: project.id,
base_id: base.id,
op_type: AuditOperationTypes.TABLE,
op_sub_type: AuditOperationSubTypes.DELETED,
op_sub_type: AuditOperationSubTypes.DELETE,
user: param.user?.email,
description: `Deleted ${table.type} ${table.table_name} with alias ${table.title} `,
ip: param.req?.clientIp,
@ -448,9 +449,9 @@ export class TablesService {
project_id: project.id,
base_id: base.id,
op_type: AuditOperationTypes.TABLE,
op_sub_type: AuditOperationSubTypes.CREATED,
op_sub_type: AuditOperationSubTypes.CREATE,
user: param.user?.email,
description: `created table ${tableCreatePayLoad.table_name} with alias ${tableCreatePayLoad.title} `,
description: `Table ${tableCreatePayLoad.table_name} with alias ${tableCreatePayLoad.title} has been created`,
ip: param.req?.clientIp,
}).then(() => {});

19
packages/nocodb-nest/src/modules/users/users.controller.ts

@ -1,4 +1,5 @@
import { promisify } from 'util';
import { AuditOperationSubTypes, AuditOperationTypes } from 'nocodb-sdk';
import {
Body,
Controller,
@ -86,8 +87,8 @@ export class UsersController {
setTokenCookie(res, refreshToken);
await Audit.insert({
op_type: 'AUTHENTICATION',
op_sub_type: 'SIGNIN',
op_type: AuditOperationTypes.AUTHENTICATION,
op_sub_type: AuditOperationSubTypes.SIGNIN,
user: user.email,
ip: req.clientIp,
description: auditDescription,
@ -113,13 +114,15 @@ export class UsersController {
return this.usersService.login(req.user);
}
@Post([
'/api/v1/auth/user/signout',
])
@UseGuards(AuthGuard('local'))
@Post('/api/v1/auth/user/signout')
@HttpCode(200)
async signout(@Request() req, @Response() res) {
return this.usersService.signout({req, res});
async signout(@Request() req, @Response() res): Promise<any> {
res.json(
await this.usersService.signout({
req,
res,
}),
);
}
@Post(`/auth/google/genTokenByCode`)

37
packages/nocodb-nest/src/modules/users/users.service.ts

@ -1,6 +1,6 @@
import { promisify } from 'util';
import { Injectable } from '@nestjs/common';
import { OrgUserRoles, validatePassword } from 'nocodb-sdk';
import { AuditOperationSubTypes, AuditOperationTypes, OrgUserRoles, validatePassword } from 'nocodb-sdk'
import { v4 as uuidv4 } from 'uuid';
import { isEmail } from 'validator';
import { T } from 'nc-help';
@ -145,10 +145,10 @@ export class UsersService {
});
await Audit.insert({
op_type: 'AUTHENTICATION',
op_sub_type: 'PASSWORD_CHANGE',
op_type: AuditOperationTypes.AUTHENTICATION,
op_sub_type: AuditOperationSubTypes.PASSWORD_CHANGE,
user: user.email,
description: `changed password `,
description: `Password has been changed`,
ip: param.req?.clientIp,
});
@ -203,10 +203,10 @@ export class UsersService {
}
await Audit.insert({
op_type: 'AUTHENTICATION',
op_sub_type: 'PASSWORD_FORGOT',
op_type: AuditOperationTypes.AUTHENTICATION,
op_sub_type: AuditOperationSubTypes.PASSWORD_FORGOT,
user: user.email,
description: `requested for password reset `,
description: `Password Reset has been requested`,
ip: param.req?.clientIp,
});
} else {
@ -279,10 +279,10 @@ export class UsersService {
});
await Audit.insert({
op_type: 'AUTHENTICATION',
op_sub_type: 'PASSWORD_RESET',
op_type: AuditOperationTypes.AUTHENTICATION,
op_sub_type: AuditOperationSubTypes.PASSWORD_RESET,
user: user.email,
description: `did reset password `,
description: `Password has been reset`,
ip: req.clientIp,
});
@ -311,10 +311,10 @@ export class UsersService {
});
await Audit.insert({
op_type: 'AUTHENTICATION',
op_sub_type: 'EMAIL_VERIFICATION',
op_type: AuditOperationTypes.AUTHENTICATION,
op_sub_type: AuditOperationSubTypes.EMAIL_VERIFICATION,
user: user.email,
description: `verified email `,
description: `Email has been verified`,
ip: req.clientIp,
});
@ -466,10 +466,10 @@ export class UsersService {
setTokenCookie(param.res, refreshToken);
await Audit.insert({
op_type: 'AUTHENTICATION',
op_sub_type: 'SIGNUP',
op_type: AuditOperationTypes.AUTHENTICATION,
op_sub_type: AuditOperationSubTypes.SIGNUP,
user: user.email,
description: `signed up `,
description: `User has signed up`,
ip: (param.req as any).clientIp,
});
@ -482,10 +482,7 @@ export class UsersService {
};
}
async signout(param: {
req: any,
res: any,
}) {
async signout(param: { res: any; req: any }) {
try {
param.res.clearCookie('refresh_token');
const user = (param.req as any).user;

124789
packages/nocodb-nest/src/schema/swagger.json

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save