feat: Update display text for auditlog entries (#7226)

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
Vishnu Narayanan
2023-06-06 01:21:45 +05:30
committed by GitHub
parent 117d5301b4
commit a01d81a7e1
2 changed files with 41 additions and 25 deletions

View File

@@ -19,13 +19,25 @@
"SUCCESS_MESSAGE": "AuditLogs retrieved successfully", "SUCCESS_MESSAGE": "AuditLogs retrieved successfully",
"ERROR_MESSAGE": "Could not connect to Woot Server, Please try again later" "ERROR_MESSAGE": "Could not connect to Woot Server, Please try again later"
}, },
"ACTION": { "DEFAULT_USER": "System",
"ADD": "created", "AUTOMATION_RULE": {
"EDIT": "updated", "ADD": "%{agentName} created a new automation rule (#%{id})",
"DELETE": "deleted", "EDIT": "%{agentName} updated an automation rule (#%{id})",
"SIGN_IN": "signed in", "DELETE": "%{agentName} deleted an automation rule (#%{id})"
"SIGN_OUT": "signed out", },
"SYSTEM": "System" "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"
} }
} }
} }

View File

@@ -96,7 +96,7 @@ export default {
methods: { methods: {
getAgentName(email) { getAgentName(email) {
if (email === null) { 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) const agentName = this.agentList.find(agent => agent.email === email)
?.name; ?.name;
@@ -104,28 +104,32 @@ export default {
return agentName || email; return agentName || email;
}, },
generateLogText(auditLogItem) { generateLogText(auditLogItem) {
const username = this.getAgentName(auditLogItem.username); const agentName = this.getAgentName(auditLogItem.username);
const auditableType = auditLogItem.auditable_type.toLowerCase(); const auditableType = auditLogItem.auditable_type.toLowerCase();
const action = auditLogItem.action.toLowerCase(); const action = auditLogItem.action.toLowerCase();
const auditId = auditLogItem.auditable_id;
const logActionKey = `${auditableType}:${action}`;
const logActions = { const translationPayload = {
create: this.$t('AUDIT_LOGS.ACTION.ADD'), agentName,
destroy: this.$t('AUDIT_LOGS.ACTION.DELETE'), id: auditId,
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'),
}; };
// detect if the action is custom user action, which involves const translationKeys = {
// only the user, such as signing in, signing out etc. 'automationrule:create': `AUDIT_LOGS.AUTOMATION_RULE.ADD`,
// if it is, then do not show the auditable type 'automationrule:update': `AUDIT_LOGS.AUTOMATION_RULE.EDIT`,
const userActions = this.getUserActions(action); 'automationrule:destroy': `AUDIT_LOGS.AUTOMATION_RULE.DELETE`,
return `${username} ${logActions[action] || action} ${ 'webhook:create': `AUDIT_LOGS.WEBHOOK.ADD`,
userActions ? '' : auditableType 'webhook:update': `AUDIT_LOGS.WEBHOOK.EDIT`,
}`; 'webhook:destroy': `AUDIT_LOGS.WEBHOOK.DELETE`,
}, 'inbox:create': `AUDIT_LOGS.INBOX.ADD`,
getUserActions(action) { 'inbox:update': `AUDIT_LOGS.INBOX.EDIT`,
return ['sign_in', 'sign_out'].includes(action); '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) { onPageChange(page) {
window.history.pushState({}, null, `${this.$route.path}?page=${page}`); window.history.pushState({}, null, `${this.$route.path}?page=${page}`);