Browse Source

chore: sync with nocodb package

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5444/head
Pranav C 2 years 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', 'LINK_RECORD',
'UNLINK_RECORD', 'UNLINK_RECORD',
'DELETE', 'DELETE',
'CREATED', 'CREATE',
'DELETED', 'RENAME',
'RENAMED',
'IMPORT_FROM_ZIP', 'IMPORT_FROM_ZIP',
'EXPORT_TO_FS', 'EXPORT_TO_FS',
'EXPORT_TO_ZIP', 'EXPORT_TO_ZIP',
'UPDATED',
'SIGNIN', 'SIGNIN',
'SIGNUP', 'SIGNUP',
'PASSWORD_RESET', 'PASSWORD_RESET',

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

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

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

@ -87,7 +87,7 @@ export class HooksController {
async tableSampleData( async tableSampleData(
@Param('tableId') tableId: string, @Param('tableId') tableId: string,
@Param('operation') operation: HookType['operation'], @Param('operation') operation: HookType['operation'],
@Param('version') version: any, //HookType['version'], @Param('version') version: HookType['version'],
) { ) {
return await this.hooksService.tableSampleData({ return await this.hooksService.tableSampleData({
tableId, 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_type: AuditOperationTypes.ORG_USER,
op_sub_type: AuditOperationSubTypes.INVITE, op_sub_type: AuditOperationSubTypes.INVITE,
user: param.req.user.email, 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, ip: param.req.clientIp,
}); });
// in case of single user check for smtp failure // in case of single user check for smtp failure
@ -239,7 +239,7 @@ export class OrgUsersService {
op_type: AuditOperationTypes.ORG_USER, op_type: AuditOperationTypes.ORG_USER,
op_sub_type: AuditOperationSubTypes.RESEND_INVITE, op_sub_type: AuditOperationSubTypes.RESEND_INVITE,
user: user.email, user: user.email,
description: `resent a invite to ${user.email} `, description: `${user.email} has been re-invited`,
ip: param.req.clientIp, 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 { Injectable } from '@nestjs/common';
import { OrgUserRoles, PluginCategory } from 'nocodb-sdk'; import { AuditOperationSubTypes, AuditOperationTypes, OrgUserRoles, PluginCategory } from 'nocodb-sdk'
import { T } from 'nc-help'; import { T } from 'nc-help';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import * as ejs from 'ejs'; import * as ejs from 'ejs';
@ -92,8 +92,8 @@ export class ProjectUsersService {
await Audit.insert({ await Audit.insert({
project_id: param.projectId, project_id: param.projectId,
op_type: 'AUTHENTICATION', op_type: AuditOperationTypes.AUTHENTICATION,
op_sub_type: 'INVITE', op_sub_type: AuditOperationSubTypes.INVITE,
user: param.req.user.email, user: param.req.user.email,
description: `invited ${email} to ${param.projectId} project `, description: `invited ${email} to ${param.projectId} project `,
ip: param.req.clientIp, ip: param.req.clientIp,
@ -121,8 +121,8 @@ export class ProjectUsersService {
await Audit.insert({ await Audit.insert({
project_id: param.projectId, project_id: param.projectId,
op_type: 'AUTHENTICATION', op_type: AuditOperationTypes.AUTHENTICATION,
op_sub_type: 'INVITE', op_sub_type: AuditOperationSubTypes.INVITE,
user: param.req.user.email, user: param.req.user.email,
description: `invited ${email} to ${param.projectId} project `, description: `invited ${email} to ${param.projectId} project `,
ip: param.req.clientIp, ip: param.req.clientIp,
@ -203,8 +203,8 @@ export class ProjectUsersService {
); );
await Audit.insert({ await Audit.insert({
op_type: 'AUTHENTICATION', op_type: AuditOperationTypes.AUTHENTICATION,
op_sub_type: 'ROLES_MANAGEMENT', op_sub_type: AuditOperationSubTypes.ROLES_MANAGEMENT,
user: param.req.user.email, user: param.req.user.email,
description: `updated roles for ${user.email} with ${param.projectUser.roles} `, description: `updated roles for ${user.email} with ${param.projectUser.roles} `,
ip: param.req.clientIp, ip: param.req.clientIp,
@ -282,8 +282,8 @@ export class ProjectUsersService {
await this.sendInviteEmail(user.email, invite_token, param.req); await this.sendInviteEmail(user.email, invite_token, param.req);
await Audit.insert({ await Audit.insert({
op_type: 'AUTHENTICATION', op_type: AuditOperationTypes.AUTHENTICATION,
op_sub_type: 'RESEND_INVITE', op_sub_type: AuditOperationSubTypes.RESEND_INVITE ,
user: user.email, user: user.email,
description: `resent a invite to ${user.email} `, description: `resent a invite to ${user.email} `,
ip: param.req.clientIp, 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 fieldName = file?.fieldname?.replace(/^_|\[\d*]$/g, '');
const filePath = sanitizeUrlPath([ const filePath = sanitizeUrlPath([
'v1', 'noco',
project.title, project.title,
model.title, model.title,
fieldName, fieldName,
@ -264,18 +264,24 @@ export class PublicDatasService {
fields[fieldName].uidt === UITypes.Attachment fields[fieldName].uidt === UITypes.Attachment
) { ) {
attachments[fieldName] = attachments[fieldName] || []; attachments[fieldName] = attachments[fieldName] || [];
const fileName = `${nanoid(6)}_${file.originalname}`; const fileName = `${nanoid(18)}${path.extname(file.originalname)}`;
let url = await storageAdapter.fileCreate(
const url = await storageAdapter.fileCreate(
slash(path.join('nc', 'uploads', ...filePath, fileName)), slash(path.join('nc', 'uploads', ...filePath, fileName)),
file, file,
); );
let attachmentPath;
// if `url` is null, then it is local attachment
if (!url) { 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({ attachments[fieldName].push({
url, ...(url ? { url } : {}),
...(attachmentPath ? { path: attachmentPath } : {}),
title: file.originalname, title: file.originalname,
mimetype: file.mimetype, mimetype: file.mimetype,
size: file.size, size: file.size,

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

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

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

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

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

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