feat: add audit trail for macros (#7352)
This commit is contained in:
@@ -43,6 +43,11 @@
|
|||||||
"ADD": "%{agentName} created a new team (#%{id})",
|
"ADD": "%{agentName} created a new team (#%{id})",
|
||||||
"EDIT": "%{agentName} updated a team (#%{id})",
|
"EDIT": "%{agentName} updated a team (#%{id})",
|
||||||
"DELETE": "%{agentName} deleted 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})"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,6 +143,9 @@ export default {
|
|||||||
'team:create': `AUDIT_LOGS.TEAM.ADD`,
|
'team:create': `AUDIT_LOGS.TEAM.ADD`,
|
||||||
'team:update': `AUDIT_LOGS.TEAM.EDIT`,
|
'team:update': `AUDIT_LOGS.TEAM.EDIT`,
|
||||||
'team:destroy': `AUDIT_LOGS.TEAM.DELETE`,
|
'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);
|
return this.$t(translationKeys[logActionKey] || '', translationPayload);
|
||||||
|
|||||||
@@ -73,3 +73,5 @@ class Macro < ApplicationRecord
|
|||||||
errors.add(:actions, "Macro execution actions #{actions.join(',')} not supported.") if actions.any?
|
errors.add(:actions, "Macro execution actions #{actions.join(',')} not supported.") if actions.any?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Macro.include_mod_with('Audit::Macro')
|
||||||
|
|||||||
7
enterprise/app/models/enterprise/audit/macro.rb
Normal file
7
enterprise/app/models/enterprise/audit/macro.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
module Enterprise::Audit::Macro
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
audited associated_with: :account
|
||||||
|
end
|
||||||
|
end
|
||||||
30
spec/enterprise/models/macro_spec.rb
Normal file
30
spec/enterprise/models/macro_spec.rb
Normal 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
|
||||||
Reference in New Issue
Block a user