From 82b73b140d75672b6ec676f2090cc77f95e0d157 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 4 Apr 2023 20:06:30 +0800 Subject: [PATCH] refactor(nocodb): revise audit description --- .../src/lib/controllers/user/user.ctl.ts | 4 +-- .../sql-data-mapper/lib/sql/BaseModelSqlv2.ts | 26 +++++++++++++------ packages/nocodb/src/lib/services/audit.svc.ts | 2 +- .../nocodb/src/lib/services/column.svc.ts | 6 ++--- .../nocodb/src/lib/services/orgUser.svc.ts | 4 +-- .../src/lib/services/projectUser.svc.ts | 6 ++--- packages/nocodb/src/lib/services/table.svc.ts | 2 +- .../nocodb/src/lib/services/user/index.ts | 10 +++---- 8 files changed, 35 insertions(+), 25 deletions(-) diff --git a/packages/nocodb/src/lib/controllers/user/user.ctl.ts b/packages/nocodb/src/lib/controllers/user/user.ctl.ts index ce37f3c0c9..c68ada72f7 100644 --- a/packages/nocodb/src/lib/controllers/user/user.ctl.ts +++ b/packages/nocodb/src/lib/controllers/user/user.ctl.ts @@ -93,7 +93,7 @@ async function signin(req, res, next) { info, req, res, - auditDescription: 'signed in', + auditDescription: 'User has signed in successfully', }) )(req, res, next); } @@ -112,7 +112,7 @@ async function googleSignin(req, res, next) { info, req, res, - auditDescription: 'signed in using Google Auth', + auditDescription: 'User has signed in successfully using Google Auth ', }) )(req, res, next); } diff --git a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts index 14dd6bbe0d..aa698dcb67 100644 --- a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts +++ b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts @@ -2296,7 +2296,7 @@ class BaseModelSqlv2 { op_type: AuditOperationTypes.DATA, op_sub_type: AuditOperationSubTypes.INSERT, description: DOMPurify.sanitize( - `${id} inserted into ${this.model.title}` + `Record with ID ${id} has been inserted into Table ${this.model.title}` ), // details: JSON.stringify(data), ip: req?.clientIp, @@ -2322,7 +2322,9 @@ class BaseModelSqlv2 { op_type: AuditOperationTypes.DATA, op_sub_type: AuditOperationSubTypes.BULK_UPDATE, description: DOMPurify.sanitize( - `${noOfUpdatedRecords} records bulk updated in ${this.model.title}` + `${noOfUpdatedRecords} ${ + noOfUpdatedRecords > 1 ? 'records have' : 'record has' + } been bulk updated in ${this.model.title}` ), // details: JSON.stringify(data), ip: req?.clientIp, @@ -2347,7 +2349,9 @@ class BaseModelSqlv2 { op_type: AuditOperationTypes.DATA, op_sub_type: AuditOperationSubTypes.BULK_DELETE, description: DOMPurify.sanitize( - `${noOfDeletedRecords} records bulk deleted in ${this.model.title}` + `${noOfDeletedRecords} ${ + noOfDeletedRecords > 1 ? 'records have' : 'record has' + } been bulk deleted in ${this.model.title}` ), // details: JSON.stringify(data), ip: req?.clientIp, @@ -2363,7 +2367,9 @@ class BaseModelSqlv2 { op_type: AuditOperationTypes.DATA, op_sub_type: AuditOperationSubTypes.BULK_INSERT, description: DOMPurify.sanitize( - `${data.length} records bulk inserted into ${this.model.title}` + `${data.length} ${ + data.length > 1 ? 'records have' : 'record has' + } been bulk inserted in ${this.model.title}` ), // details: JSON.stringify(data), ip: req?.clientIp, @@ -2396,7 +2402,9 @@ class BaseModelSqlv2 { row_id: id, op_type: AuditOperationTypes.DATA, op_sub_type: AuditOperationSubTypes.UPDATE, - description: DOMPurify.sanitize(`${id} updated in ${this.model.title}`), + description: DOMPurify.sanitize( + `Record with ID ${id} has been updated in Table ${this.model.title}` + ), // details: JSON.stringify(data), ip: req?.clientIp, user: req?.user?.email, @@ -2424,7 +2432,9 @@ class BaseModelSqlv2 { row_id: id, op_type: AuditOperationTypes.DATA, op_sub_type: AuditOperationSubTypes.DELETE, - description: DOMPurify.sanitize(`${id} deleted from ${this.model.title}`), + description: DOMPurify.sanitize( + `Record with ID ${id} has been deleted in Table ${this.model.title}` + ), // details: JSON.stringify(data), ip: req?.clientIp, user: req?.user?.email, @@ -2695,7 +2705,7 @@ class BaseModelSqlv2 { op_sub_type: AuditOperationSubTypes.LINK_RECORD, row_id: rowId, description: DOMPurify.sanitize( - `Record [id:${childId}] record linked with record [id:${rowId}] record in ${this.model.title}` + `Record [id:${childId}] has been linked with record [id:${rowId}] in ${this.model.title}` ), // details: JSON.stringify(data), ip: req?.clientIp, @@ -2797,7 +2807,7 @@ class BaseModelSqlv2 { op_sub_type: AuditOperationSubTypes.UNLINK_RECORD, row_id: rowId, description: DOMPurify.sanitize( - `Record [id:${childId}] record unlinked with record [id:${rowId}] record in ${this.model.title}` + `Record [id:${childId}] has been unlinked with record [id:${rowId}] in ${this.model.title}` ), // details: JSON.stringify(data), ip: req?.clientIp, diff --git a/packages/nocodb/src/lib/services/audit.svc.ts b/packages/nocodb/src/lib/services/audit.svc.ts index d88fdf5e26..c941800827 100644 --- a/packages/nocodb/src/lib/services/audit.svc.ts +++ b/packages/nocodb/src/lib/services/audit.svc.ts @@ -36,7 +36,7 @@ export async function auditRowUpdate(param: { op_type: AuditOperationTypes.DATA, op_sub_type: AuditOperationSubTypes.UPDATE, description: DOMPurify.sanitize( - `Table ${model.table_name} : field ${param.body.column_name} got changed from ${param.body.prev_value} to ${param.body.value}` + `The column ${param.body.column_name} in Table ${model.table_name} has been changed from ${param.body.prev_value} to ${param.body.value}` ), details: DOMPurify.sanitize(`${param.body.column_name} : ${param.body.prev_value} diff --git a/packages/nocodb/src/lib/services/column.svc.ts b/packages/nocodb/src/lib/services/column.svc.ts index 320d1c5c72..4fa6a6c5ef 100644 --- a/packages/nocodb/src/lib/services/column.svc.ts +++ b/packages/nocodb/src/lib/services/column.svc.ts @@ -824,7 +824,7 @@ export async function columnUpdate(param: { op_type: AuditOperationTypes.TABLE_COLUMN, 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}`, + description: `The column ${column.column_name} with alias ${column.title} from table ${table.table_name} has been updated`, ip: param.req?.clientIp, }).then(() => {}); @@ -1129,7 +1129,7 @@ export async function columnAdd(param: { op_type: AuditOperationTypes.TABLE_COLUMN, 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}`, + description: `The column ${colBody.column_name} with alias ${colBody.title} from table ${table.table_name} has been created`, ip: param?.req.clientIp, }).then(() => {}); @@ -1341,7 +1341,7 @@ export async function columnDelete(param: { req?: any; columnId: string }) { op_type: AuditOperationTypes.TABLE_COLUMN, 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}`, + description: `The column ${column.column_name} with alias ${column.title} from table ${table.table_name} has been deleted`, ip: param?.req.clientIp, }).then(() => {}); diff --git a/packages/nocodb/src/lib/services/orgUser.svc.ts b/packages/nocodb/src/lib/services/orgUser.svc.ts index a3f79d0d2a..38c19bf9a1 100644 --- a/packages/nocodb/src/lib/services/orgUser.svc.ts +++ b/packages/nocodb/src/lib/services/orgUser.svc.ts @@ -147,7 +147,7 @@ export async function userAdd(param: { 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 @@ -218,7 +218,7 @@ export async function userInviteResend(param: { 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, }); diff --git a/packages/nocodb/src/lib/services/projectUser.svc.ts b/packages/nocodb/src/lib/services/projectUser.svc.ts index 56ecea6948..bd3d7a2b4c 100644 --- a/packages/nocodb/src/lib/services/projectUser.svc.ts +++ b/packages/nocodb/src/lib/services/projectUser.svc.ts @@ -98,7 +98,7 @@ export async function userInvite(param: { op_type: AuditOperationTypes.AUTHENTICATION, 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, }); } else { @@ -209,7 +209,7 @@ export async function projectUserUpdate(param: { 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} `, + description: `Roles for ${user.email} with has been updated to ${param.projectUser.roles}`, ip: param.req.clientIp, }); @@ -281,7 +281,7 @@ export async function projectUserInviteResend(param: { op_type: AuditOperationTypes.AUTHENTICATION, 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, project_id: param.projectId, }); diff --git a/packages/nocodb/src/lib/services/table.svc.ts b/packages/nocodb/src/lib/services/table.svc.ts index e8b21935f2..fa36f647a3 100644 --- a/packages/nocodb/src/lib/services/table.svc.ts +++ b/packages/nocodb/src/lib/services/table.svc.ts @@ -435,7 +435,7 @@ export async function tableCreate(param: { op_type: AuditOperationTypes.TABLE, 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(() => {}); diff --git a/packages/nocodb/src/lib/services/user/index.ts b/packages/nocodb/src/lib/services/user/index.ts index 796365a017..1afa86648e 100644 --- a/packages/nocodb/src/lib/services/user/index.ts +++ b/packages/nocodb/src/lib/services/user/index.ts @@ -127,7 +127,7 @@ export async function passwordChange(param: { 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, }); @@ -185,7 +185,7 @@ export async function passwordForgot(param: { 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 { @@ -261,7 +261,7 @@ export async function passwordReset(param: { 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, }); @@ -293,7 +293,7 @@ export async function emailVerification(param: { op_type: AuditOperationTypes.AUTHENTICATION, op_sub_type: AuditOperationSubTypes.EMAIL_VERIFICATION, user: user.email, - description: `verified email `, + description: `Email has been verified`, ip: req.clientIp, }); @@ -449,7 +449,7 @@ export async function signup(param: { 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, });