audited_logfile 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/audited_logfile.rb +38 -7
- metadata +2 -2
data/lib/audited_logfile.rb
CHANGED
@@ -25,6 +25,20 @@ module AuditedLogfile
|
|
25
25
|
def self.skip
|
26
26
|
@@skip || []
|
27
27
|
end
|
28
|
+
|
29
|
+
module ActiveRecord
|
30
|
+
class LogSubscriber < ActiveSupport::LogSubscriber
|
31
|
+
def sql(event)
|
32
|
+
if event.payload[:sql] =~ /\ASELECT/i
|
33
|
+
user = Thread.current[:sql_audit_user]
|
34
|
+
user_info = user ? "#{user.class}(#{user.id}): #{user.try(:email)}" : 'Unknown'
|
35
|
+
AuditedLogfile.logger.info "#{Time.now.iso8601(1)}, SELECT, #{user_info}, `#{event.payload[:sql]}`"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
attach_to :active_record
|
40
|
+
end
|
41
|
+
end
|
28
42
|
end
|
29
43
|
|
30
44
|
module Audited
|
@@ -32,12 +46,18 @@ module Audited
|
|
32
46
|
module ActiveRecord
|
33
47
|
class Audit < ::ActiveRecord::Base
|
34
48
|
before_create do |record|
|
35
|
-
changes
|
36
|
-
|
37
|
-
|
38
|
-
|
49
|
+
if changes.is_a? Hash
|
50
|
+
changes = audited_changes.map { |k, v| "#{k}: #{v.is_a?(Array) ? "[#{v.first.inspect}, #{v.last.inspect}]" : v}"}.join(', ')
|
51
|
+
end
|
52
|
+
|
53
|
+
user_info = user ? "#{user_type}(#{user_id}): #{user.try(:email)}" : 'Unknown'
|
54
|
+
common_log = "#{Time.now.iso8601(1)}, #{action.upcase}, #{user_info}"
|
55
|
+
|
56
|
+
case action
|
57
|
+
when 'report'
|
58
|
+
AuditedLogfile.logger.info "#{common_log}, #{audited_changes.inspect}"
|
39
59
|
else
|
40
|
-
AuditedLogfile.logger.info "#{
|
60
|
+
AuditedLogfile.logger.info "#{common_log}, #{auditable_type}, #{auditable_id}, (#{changes})"
|
41
61
|
end
|
42
62
|
end
|
43
63
|
end
|
@@ -45,6 +65,17 @@ module Audited
|
|
45
65
|
end
|
46
66
|
|
47
67
|
class Sweeper < ActiveModel::Observer
|
68
|
+
def before(controller)
|
69
|
+
self.controller = controller
|
70
|
+
Thread.current[:sql_audit_user] = current_user
|
71
|
+
true
|
72
|
+
end
|
73
|
+
|
74
|
+
def after(controller)
|
75
|
+
self.controller = nil
|
76
|
+
Thread.current[:sql_audit_user] = nil
|
77
|
+
end
|
78
|
+
|
48
79
|
def current_user
|
49
80
|
if Audited.current_user_method.is_a? Array
|
50
81
|
Audited.current_user_method.map do |method|
|
@@ -80,11 +111,11 @@ module ActiveRecord
|
|
80
111
|
end
|
81
112
|
|
82
113
|
Warden::Manager.after_authentication do |user,auth,opts|
|
83
|
-
user_info = user.present? ? "#{user.class}(#{user.id}): #{user.email}" : '
|
114
|
+
user_info = user.present? ? "#{user.class}(#{user.id}): #{user.email}" : 'Unknown'
|
84
115
|
AuditedLogfile.logger.info "#{Time.now.iso8601(1)}, SIGNIN, #{user_info}"
|
85
116
|
end
|
86
117
|
|
87
118
|
Warden::Manager.before_logout do |user,auth,scope|
|
88
|
-
user_info = user.present? ? "#{user.class}(#{user.id}): #{user.email}" : '
|
119
|
+
user_info = user.present? ? "#{user.class}(#{user.id}): #{user.email}" : 'Unknown'
|
89
120
|
AuditedLogfile.logger.info "#{Time.now.iso8601(1)}, SIGNOUT, #{user_info}"
|
90
121
|
end
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: audited_logfile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.9
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Alexander Kiseliov
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
version_requirements: !ruby/object:Gem::Requirement
|