feat: add audit trail for macros (#7352)

This commit is contained in:
Vishnu Narayanan
2023-06-20 13:04:59 +05:30
committed by GitHub
parent afb7e67795
commit 6bea2cbc4a
5 changed files with 47 additions and 0 deletions

View File

@@ -43,6 +43,11 @@
"ADD": "%{agentName} created a new team (#%{id})",
"EDIT": "%{agentName} updated a team (#%{id})",
"DELETE": "%{agentName} deleted a team (#%{id})"
},
"MACRO": {
"ADD": "%{agentName} created a new macro (#%{id})",
"EDIT": "%{agentName} updated a macro (#%{id})",
"DELETE": "%{agentName} deleted a macro (#%{id})"
}
}
}

View File

@@ -143,6 +143,9 @@ export default {
'team:create': `AUDIT_LOGS.TEAM.ADD`,
'team:update': `AUDIT_LOGS.TEAM.EDIT`,
'team:destroy': `AUDIT_LOGS.TEAM.DELETE`,
'macro:create': `AUDIT_LOGS.MACRO.ADD`,
'macro:update': `AUDIT_LOGS.MACRO.EDIT`,
'macro:destroy': `AUDIT_LOGS.MACRO.DELETE`,
};
return this.$t(translationKeys[logActionKey] || '', translationPayload);

View File

@@ -73,3 +73,5 @@ class Macro < ApplicationRecord
errors.add(:actions, "Macro execution actions #{actions.join(',')} not supported.") if actions.any?
end
end
Macro.include_mod_with('Audit::Macro')

View File

@@ -0,0 +1,7 @@
module Enterprise::Audit::Macro
extend ActiveSupport::Concern
included do
audited associated_with: :account
end
end

View File

@@ -0,0 +1,30 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Macro do
let(:account) { create(:account) }
let!(:macro) { create(:macro, account: account) }
describe 'audit log' do
context 'when macro is created' do
it 'has associated audit log created' do
expect(Audited::Audit.where(auditable_type: 'Macro', action: 'create').count).to eq 1
end
end
context 'when macro is updated' do
it 'has associated audit log created' do
macro.update(name: 'awesome macro')
expect(Audited::Audit.where(auditable_type: 'Macro', action: 'update').count).to eq 1
end
end
context 'when macro is deleted' do
it 'has associated audit log created' do
macro.destroy!
expect(Audited::Audit.where(auditable_type: 'Macro', action: 'destroy').count).to eq 1
end
end
end
end