From a01d81a7e168f3eae6c2601eb46f63e4949b11cd Mon Sep 17 00:00:00 2001 From: Vishnu Narayanan Date: Tue, 6 Jun 2023 01:21:45 +0530 Subject: [PATCH] feat: Update display text for auditlog entries (#7226) Co-authored-by: Pranav Raj S --- .../dashboard/i18n/locale/en/auditLogs.json | 26 ++++++++---- .../dashboard/settings/auditlogs/Index.vue | 40 ++++++++++--------- 2 files changed, 41 insertions(+), 25 deletions(-) diff --git a/app/javascript/dashboard/i18n/locale/en/auditLogs.json b/app/javascript/dashboard/i18n/locale/en/auditLogs.json index a2bb40135..b1653e027 100644 --- a/app/javascript/dashboard/i18n/locale/en/auditLogs.json +++ b/app/javascript/dashboard/i18n/locale/en/auditLogs.json @@ -19,13 +19,25 @@ "SUCCESS_MESSAGE": "AuditLogs retrieved successfully", "ERROR_MESSAGE": "Could not connect to Woot Server, Please try again later" }, - "ACTION": { - "ADD": "created", - "EDIT": "updated", - "DELETE": "deleted", - "SIGN_IN": "signed in", - "SIGN_OUT": "signed out", - "SYSTEM": "System" + "DEFAULT_USER": "System", + "AUTOMATION_RULE": { + "ADD": "%{agentName} created a new automation rule (#%{id})", + "EDIT": "%{agentName} updated an automation rule (#%{id})", + "DELETE": "%{agentName} deleted an automation rule (#%{id})" + }, + "INBOX": { + "ADD": "%{agentName} created a new inbox (#%{id})", + "EDIT": "%{agentName} updated an inbox (#%{id})", + "DELETE": "%{agentName} deleted an inbox (#%{id})" + }, + "WEBHOOK": { + "ADD": "%{agentName} created a new webhook (#%{id})", + "EDIT": "%{agentName} updated a webhook (#%{id})", + "DELETE": "%{agentName} deleted a webhook (#%{id})" + }, + "USER_ACTION": { + "SIGN_IN": "%{agentName} signed in", + "SIGN_OUT": "%{agentName} signed out" } } } diff --git a/app/javascript/dashboard/routes/dashboard/settings/auditlogs/Index.vue b/app/javascript/dashboard/routes/dashboard/settings/auditlogs/Index.vue index f11bbb6f4..d7d94f2e8 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/auditlogs/Index.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/auditlogs/Index.vue @@ -96,7 +96,7 @@ export default { methods: { getAgentName(email) { if (email === null) { - return this.$t('AUDIT_LOGS.ACTION.SYSTEM'); + return this.$t('AUDIT_LOGS.DEFAULT_USER'); } const agentName = this.agentList.find(agent => agent.email === email) ?.name; @@ -104,28 +104,32 @@ export default { return agentName || email; }, generateLogText(auditLogItem) { - const username = this.getAgentName(auditLogItem.username); + const agentName = this.getAgentName(auditLogItem.username); const auditableType = auditLogItem.auditable_type.toLowerCase(); const action = auditLogItem.action.toLowerCase(); + const auditId = auditLogItem.auditable_id; + const logActionKey = `${auditableType}:${action}`; - const logActions = { - create: this.$t('AUDIT_LOGS.ACTION.ADD'), - destroy: this.$t('AUDIT_LOGS.ACTION.DELETE'), - update: this.$t('AUDIT_LOGS.ACTION.EDIT'), - sign_in: this.$t('AUDIT_LOGS.ACTION.SIGN_IN'), - sign_out: this.$t('AUDIT_LOGS.ACTION.SIGN_OUT'), + const translationPayload = { + agentName, + id: auditId, }; - // detect if the action is custom user action, which involves - // only the user, such as signing in, signing out etc. - // if it is, then do not show the auditable type - const userActions = this.getUserActions(action); - return `${username} ${logActions[action] || action} ${ - userActions ? '' : auditableType - }`; - }, - getUserActions(action) { - return ['sign_in', 'sign_out'].includes(action); + const translationKeys = { + 'automationrule:create': `AUDIT_LOGS.AUTOMATION_RULE.ADD`, + 'automationrule:update': `AUDIT_LOGS.AUTOMATION_RULE.EDIT`, + 'automationrule:destroy': `AUDIT_LOGS.AUTOMATION_RULE.DELETE`, + 'webhook:create': `AUDIT_LOGS.WEBHOOK.ADD`, + 'webhook:update': `AUDIT_LOGS.WEBHOOK.EDIT`, + 'webhook:destroy': `AUDIT_LOGS.WEBHOOK.DELETE`, + 'inbox:create': `AUDIT_LOGS.INBOX.ADD`, + 'inbox:update': `AUDIT_LOGS.INBOX.EDIT`, + 'inbox:destroy': `AUDIT_LOGS.INBOX.DELETE`, + 'user:sign_in': `AUDIT_LOGS.USER_ACTION.SIGN_IN`, + 'user:sign_out': `AUDIT_LOGS.USER_ACTION.SIGN_OUT`, + }; + + return this.$t(translationKeys[logActionKey] || '', translationPayload); }, onPageChange(page) { window.history.pushState({}, null, `${this.$route.path}?page=${page}`);