Sha256: 7bbffdf2420852fac9ae8a5aeb2ea2a76d595a2299d15d1acf63fdb7465fd6cb
Contents?: true
Size: 1.27 KB
Versions: 1
Compression:
Stored size: 1.27 KB
Contents
module Weasel def audit_with_weasel(*args) around_filter :audit, only: args end module Auditable def audit begin yield ensure return unless actor.present? Weasel::EventsWorker.perform_async(actor.class.name, actor.id, request_data) end end private def actor return current_user if defined?(current_user) return current_admin if defined?(current_admin) end def request_data parameters = if request.respond_to?(:filtered_parameters) request.filtered_parameters else request.params end rails_action = "#{parameters[:controller]}:#{parameters[:action]}" rails_parameters = parameters.except(:controller, :action) { action: rails_action, params: rails_parameters, remote_ip: request.remote_ip, geo_ip_information: geo_ip_information, user_agent: request.user_agent, response: { status: response.status }.tap do |hash| hash[:body] = response.body if response.body end } end def geo_ip_information geo_service.country(request.remote_ip).to_h end def geo_service @@geoip ||= GeoIP.new(File.join(Rails.root, 'tmp/GeoIP.dat')) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
weasel-0.2.9 | lib/weasel/concerns/auditable.rb |