Browse Source

refactor(nocodb): use values from AuditOperationTypes & AuditOperationSubTypes

pull/5403/head
Wing-Kam Wong 2 years ago
parent
commit
5da7b0d261
  1. 5
      packages/nocodb/src/lib/controllers/user/user.ctl.ts
  2. 24
      packages/nocodb/src/lib/services/projectUser.svc.ts
  3. 28
      packages/nocodb/src/lib/services/user/index.ts

5
packages/nocodb/src/lib/controllers/user/user.ctl.ts

@ -1,4 +1,5 @@
import { promisify } from 'util'; import { promisify } from 'util';
import { AuditOperationSubTypes, AuditOperationTypes } from 'nocodb-sdk';
import * as ejs from 'ejs'; import * as ejs from 'ejs';
import passport from 'passport'; import passport from 'passport';
import catchError, { NcError } from '../../meta/helpers/catchError'; import catchError, { NcError } from '../../meta/helpers/catchError';
@ -65,8 +66,8 @@ async function successfulSignIn({
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,

24
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 { T } from 'nc-help';
import validator from 'validator'; import validator from 'validator';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import * as ejs from 'ejs'; import * as ejs from 'ejs';
import { PluginCategory } from 'nocodb-sdk';
import { validatePayload } from '../meta/api/helpers'; import { validatePayload } from '../meta/api/helpers';
import { PagedResponseImpl } from '../meta/helpers/PagedResponse'; import { PagedResponseImpl } from '../meta/helpers/PagedResponse';
import ProjectUser from '../models/ProjectUser'; import ProjectUser from '../models/ProjectUser';
@ -91,8 +95,8 @@ export async function userInvite(param: {
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,
@ -120,8 +124,8 @@ export async function userInvite(param: {
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,
@ -202,8 +206,8 @@ export async function projectUserUpdate(param: {
); );
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,
@ -274,8 +278,8 @@ export async function projectUserInviteResend(param: {
await sendInviteEmail(user.email, invite_token, param.req); await 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,

28
packages/nocodb/src/lib/services/user/index.ts

@ -1,6 +1,10 @@
import { promisify } from 'util'; import { promisify } from 'util';
import { validatePassword } from 'nocodb-sdk'; import {
import { OrgUserRoles } from 'nocodb-sdk'; AuditOperationSubTypes,
AuditOperationTypes,
OrgUserRoles,
validatePassword,
} from 'nocodb-sdk';
import { T } from 'nc-help'; import { T } from 'nc-help';
import * as ejs from 'ejs'; import * as ejs from 'ejs';
import bcrypt from 'bcryptjs'; import bcrypt from 'bcryptjs';
@ -120,8 +124,8 @@ export async function passwordChange(param: {
}); });
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: `changed password `,
ip: param.req?.clientIp, ip: param.req?.clientIp,
@ -178,8 +182,8 @@ export async function passwordForgot(param: {
} }
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: `requested for password reset `,
ip: param.req?.clientIp, ip: param.req?.clientIp,
@ -254,8 +258,8 @@ export async function passwordReset(param: {
}); });
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: `did reset password `,
ip: req.clientIp, ip: req.clientIp,
@ -286,8 +290,8 @@ export async function emailVerification(param: {
}); });
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: `verified email `,
ip: req.clientIp, ip: req.clientIp,
@ -442,8 +446,8 @@ export async function signup(param: {
user = (param.req as any).user; user = (param.req as any).user;
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: `signed up `,
ip: (param.req as any).clientIp, ip: (param.req as any).clientIp,

Loading…
Cancel
Save