From 5da7b0d261e6d2af7e6b97cc1c84daa4a09aeef6 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 4 Apr 2023 17:31:30 +0800 Subject: [PATCH] refactor(nocodb): use values from AuditOperationTypes & AuditOperationSubTypes --- .../src/lib/controllers/user/user.ctl.ts | 5 ++-- .../src/lib/services/projectUser.svc.ts | 24 +++++++++------- .../nocodb/src/lib/services/user/index.ts | 28 +++++++++++-------- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/packages/nocodb/src/lib/controllers/user/user.ctl.ts b/packages/nocodb/src/lib/controllers/user/user.ctl.ts index b411db0e39..ce37f3c0c9 100644 --- a/packages/nocodb/src/lib/controllers/user/user.ctl.ts +++ b/packages/nocodb/src/lib/controllers/user/user.ctl.ts @@ -1,4 +1,5 @@ import { promisify } from 'util'; +import { AuditOperationSubTypes, AuditOperationTypes } from 'nocodb-sdk'; import * as ejs from 'ejs'; import passport from 'passport'; import catchError, { NcError } from '../../meta/helpers/catchError'; @@ -65,8 +66,8 @@ async function successfulSignIn({ 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, diff --git a/packages/nocodb/src/lib/services/projectUser.svc.ts b/packages/nocodb/src/lib/services/projectUser.svc.ts index bc60f7a844..56ecea6948 100644 --- a/packages/nocodb/src/lib/services/projectUser.svc.ts +++ b/packages/nocodb/src/lib/services/projectUser.svc.ts @@ -1,9 +1,13 @@ -import { OrgUserRoles } from 'nocodb-sdk'; +import { + AuditOperationSubTypes, + AuditOperationTypes, + OrgUserRoles, + PluginCategory, +} from 'nocodb-sdk'; import { T } from 'nc-help'; import validator from 'validator'; import { v4 as uuidv4 } from 'uuid'; import * as ejs from 'ejs'; -import { PluginCategory } from 'nocodb-sdk'; import { validatePayload } from '../meta/api/helpers'; import { PagedResponseImpl } from '../meta/helpers/PagedResponse'; import ProjectUser from '../models/ProjectUser'; @@ -91,8 +95,8 @@ export async function userInvite(param: { 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, @@ -120,8 +124,8 @@ export async function userInvite(param: { 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, @@ -202,8 +206,8 @@ export async function projectUserUpdate(param: { ); 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, @@ -274,8 +278,8 @@ export async function projectUserInviteResend(param: { await 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, diff --git a/packages/nocodb/src/lib/services/user/index.ts b/packages/nocodb/src/lib/services/user/index.ts index a082ff9070..796365a017 100644 --- a/packages/nocodb/src/lib/services/user/index.ts +++ b/packages/nocodb/src/lib/services/user/index.ts @@ -1,6 +1,10 @@ import { promisify } from 'util'; -import { validatePassword } from 'nocodb-sdk'; -import { OrgUserRoles } from 'nocodb-sdk'; +import { + AuditOperationSubTypes, + AuditOperationTypes, + OrgUserRoles, + validatePassword, +} from 'nocodb-sdk'; import { T } from 'nc-help'; import * as ejs from 'ejs'; import bcrypt from 'bcryptjs'; @@ -120,8 +124,8 @@ export async function passwordChange(param: { }); 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 `, ip: param.req?.clientIp, @@ -178,8 +182,8 @@ export async function passwordForgot(param: { } 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 `, ip: param.req?.clientIp, @@ -254,8 +258,8 @@ export async function passwordReset(param: { }); 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 `, ip: req.clientIp, @@ -286,8 +290,8 @@ export async function emailVerification(param: { }); 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 `, ip: req.clientIp, @@ -442,8 +446,8 @@ export async function signup(param: { user = (param.req as any).user; 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 `, ip: (param.req as any).clientIp,