iachat/enterprise/app/models/enterprise/audit/team_member.rb
Gabriel Jablonski 659c3e7c2f chore: apply Rails/SaveBang cop (#15)
* chore: apply Rails/SaveBang cop

* fix: correct locale validation in category model spec

* fix: update save methods to avoid Rails/SaveBang cop violations
2025-04-03 23:29:24 -03:00

32 lines
736 B
Ruby

module Enterprise::Audit::TeamMember
extend ActiveSupport::Concern
included do
after_commit :create_audit_log_entry_on_create, on: :create
after_commit :create_audit_log_entry_on_delete, on: :destroy
end
private
def create_audit_log_entry_on_create
create_audit_log_entry('create')
end
def create_audit_log_entry_on_delete
create_audit_log_entry('destroy')
end
def create_audit_log_entry(action)
return if team.blank?
Enterprise::AuditLog.create!(
auditable_id: id,
auditable_type: 'TeamMember',
action: action,
associated_id: team&.account_id,
audited_changes: attributes.except('updated_at', 'created_at'),
associated_type: 'Account'
)
end
end