Class: SolidStackWeb::AuditController

Inherits:
ApplicationController show all
Defined in:
app/controllers/solid_stack_web/audit_controller.rb

Constant Summary

Constants inherited from ApplicationController

SolidStackWeb::ApplicationController::PERIOD_DURATIONS

Instance Method Summary collapse

Instance Method Details

#indexObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/solid_stack_web/audit_controller.rb', line 3

def index
  unless AuditEvent.table_exists?
    redirect_to root_path,
                alert: "Audit log requires running `rails solid_stack_web:install:migrations && rails db:migrate`."
    return
  end

  set_filters
  scope = audit_scope

  respond_to do |format|
    format.html { @pagy, @events = pagy(scope) }
    format.csv do
      send_data audit_csv(scope),
                filename: "audit-log-#{Date.today}.csv",
                type: "text/csv", disposition: "attachment"
    end
  end
end