|
# app/admin/admin_audit_log.rb |
|
ActiveAdmin.register Admin::AuditLog, as: "Admin Audit Log" do |
|
menu label: "Admin Audit Log", parent: :menu_settings |
|
|
|
actions :index, :show |
|
|
|
remove_filter :resource_changes, :params, :ip_address, :user_agent, :session_id, :controller, :action, :username |
|
|
|
config.sort_order = "created_at_desc" |
|
|
|
index title: "Audit Log", download_links: [:csv], pagination_total: false do |
|
column "Time", sortable: :created_at do |log_entry| |
|
link_to(log_entry.created_at.to_fs(:rfc822), admin_admin_audit_log_path(log_entry)) |
|
end |
|
column :user do |log_entry| |
|
next "#{log_entry.username} (deleted)" if log_entry.user.nil? |
|
|
|
link_to(log_entry.username, log_entry.user) |
|
end |
|
column :action, sortable: false do |log_entry| |
|
"#{log_entry.controller} # #{log_entry.action}" |
|
end |
|
column :resource do |log_entry| |
|
next unless log_entry.resource_type && log_entry.resource_id |
|
|
|
resource_name = log_entry.resource_type.underscore.humanize |
|
next "#{resource_name} (deleted)" unless log_entry.resource |
|
|
|
link_to("#{resource_name} #{log_entry.resource.to_param}", [:admin, log_entry.resource]) |
|
end |
|
end |
|
|
|
show title: ->(log_entry) { "Event ##{log_entry.id}" } do |
|
attributes_table do |
|
row :resource_type do |log_entry| |
|
log_entry.resource_type&.underscore&.humanize |
|
end |
|
row :resource_id do |log_entry| |
|
next unless log_entry.resource |
|
|
|
link_to(log_entry.resource_id, [:admin, log_entry.resource]) |
|
end |
|
row :action do |log_entry| |
|
"#{log_entry.controller} # #{log_entry.action}" |
|
end |
|
row :user do |log_entry| |
|
next "#{log_entry.username} (deleted)" if log_entry.user.nil? |
|
|
|
link_to(log_entry.username, log_entry.user) |
|
end |
|
row :resource_changes do |log_entry| |
|
table_for log_entry.resource_changes.to_a, style: "overflow-x:scroll;" do |
|
column :attribute do |attribute, _changes| |
|
attribute |
|
end |
|
column :before do |_attribute, changes| |
|
changes[0].to_json |
|
end |
|
column :after do |_attribute, changes| |
|
changes[1].to_json |
|
end |
|
end |
|
end |
|
row :params do |log_entry| |
|
log_entry.params.to_json |
|
end |
|
row :ip_address do |log_entry| |
|
log_entry.ip_address |
|
end |
|
row :user_agent do |log_entry| |
|
log_entry.user_agent |
|
end |
|
row :session_id do |log_entry| |
|
span log_entry.session_id |
|
|
|
if log_entry.session_id != session.id && Session.exists?(session_id: log_entry.session_id) |
|
small \ |
|
link_to "Revoke", |
|
revoke_session_admin_user_path(log_entry.user, session_id: log_entry.session_id), |
|
method: :delete, |
|
data: {confirm: "Are you sure you want to revoke this session?"} |
|
end |
|
end |
|
end |
|
end |
|
end |