Module: AuditLog
- Defined in:
- lib/audit-log.rb,
lib/audit-log/model.rb,
lib/audit-log/engine.rb,
lib/audit-log/version.rb,
app/models/audit_log/log.rb,
lib/audit-log/configuration.rb,
lib/audit-log/log_subscriber.rb,
lib/audit-log/controller_helper.rb,
app/controllers/audit_log/logs_controller.rb,
lib/generators/audit_log/install_generator.rb
Defined Under Namespace
Modules: ControllerHelper, Generators, Model Classes: Configuration, Engine, Log, LogSubscriber, LogsController
Constant Summary collapse
- VERSION =
"1.2.0"
Class Method Summary collapse
-
.action_options ⇒ Object
Get I18n action name options for select.
-
.audit!(action, record = nil, payload: nil, user: nil, request: nil) ⇒ Object
Create an audit log.
- .config ⇒ Object
- .configure(&block) ⇒ Object
Class Method Details
.action_options ⇒ Object
Get I18n action name options for select
58 59 60 |
# File 'lib/audit-log.rb', line 58 def I18n.t("audit_log.action").map { |k, v| [v, k.to_s] } end |
.audit!(action, record = nil, payload: nil, user: nil, request: nil) ⇒ Object
Create an audit log
AuditLog.audit!(:edit_account, @account, payload: account_params, user: current_user)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/audit-log.rb', line 30 def audit!(action, record = nil, payload: nil, user: nil, request: nil) ActiveSupport::Notifications.instrument("audit.audit_log", action: action) do request_info = {} if request request_info = { request_id: request.request_id, ip: request.remote_ip, url: request.url, user_agent: request.user_agent } end # Set nil if record is a new_record, do this for avoid create record. record = nil if record&.new_record? Rails.logger.silence do AuditLog::Log.create!( action: action, record: record, payload: (payload || {}).to_h.deep_stringify_keys, user: user, request: request_info.deep_stringify_keys ) end end end |
.config ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/audit-log.rb', line 12 def config return @config if defined?(@config) @config = Configuration.new @config.user_class = "User" @config.current_user_method = "current_user" @config.user_name_method = "name" @config.table_name = "audit_logs" @config end |
.configure(&block) ⇒ Object
23 24 25 |
# File 'lib/audit-log.rb', line 23 def configure(&block) config.instance_exec(&block) end |