pg_audit_log 0.5.2 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -47,6 +47,10 @@ class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
|
|
47
47
|
true
|
48
48
|
end
|
49
49
|
|
50
|
+
def set_user_id(user_id = nil)
|
51
|
+
execute_without_pg_audit_log PgAuditLog::Function::user_identifier_temporary_function(user_id || @last_user_id)
|
52
|
+
end
|
53
|
+
|
50
54
|
def blank_audit_user_id_and_name
|
51
55
|
@last_user_id = @last_unique_name = nil
|
52
56
|
true
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module PgAuditLog
|
2
2
|
class Function < PgAuditLog::ActiveRecord
|
3
|
+
DISABLED_USER = -2396
|
4
|
+
|
3
5
|
class << self
|
4
6
|
def name
|
5
7
|
"audit_changes"
|
@@ -45,6 +47,11 @@ module PgAuditLog
|
|
45
47
|
unique_name varchar;
|
46
48
|
column_name varchar;
|
47
49
|
BEGIN
|
50
|
+
user_identifier := pg_temp.pg_audit_log_user_identifier();
|
51
|
+
IF user_identifier = #{DISABLED_USER} THEN
|
52
|
+
RETURN NULL;
|
53
|
+
END IF;
|
54
|
+
unique_name := pg_temp.pg_audit_log_user_unique_name();
|
48
55
|
primary_key_column := NULL;
|
49
56
|
EXECUTE 'SELECT pg_attribute.attname
|
50
57
|
FROM pg_index, pg_class, pg_attribute
|
@@ -54,8 +61,6 @@ module PgAuditLog
|
|
54
61
|
AND pg_attribute.attnum = any(pg_index.indkey)
|
55
62
|
AND indisprimary'
|
56
63
|
INTO primary_key_column USING TG_RELNAME;
|
57
|
-
user_identifier := pg_temp.pg_audit_log_user_identifier();
|
58
|
-
unique_name := pg_temp.pg_audit_log_user_unique_name();
|
59
64
|
primary_key_value := NULL;
|
60
65
|
|
61
66
|
FOR col IN SELECT * FROM information_schema.columns WHERE table_name = TG_RELNAME LOOP
|
@@ -49,15 +49,11 @@ module PgAuditLog
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def enable
|
52
|
-
|
53
|
-
enable_for_table(table)
|
54
|
-
end
|
52
|
+
connection.set_user_id(nil)
|
55
53
|
end
|
56
54
|
|
57
55
|
def disable
|
58
|
-
|
59
|
-
disable_for_table(table)
|
60
|
-
end
|
56
|
+
connection.set_user_id(PgAuditLog::Function::DISABLED_USER)
|
61
57
|
end
|
62
58
|
|
63
59
|
def without_triggers
|
data/lib/pg_audit_log/version.rb
CHANGED
data/pg_audit_log.gemspec
CHANGED
@@ -11,6 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.homepage = "https://github.com/Casecommons/pg_audit_log"
|
12
12
|
s.summary = %q{postgresql only database-level audit logging of all databases changes}
|
13
13
|
s.description = %q{A completely transparent audit logging component for your application using a stored procedure and triggers. Comes with specs for your project and a rake task to generate the reverse SQL to undo changes logged}
|
14
|
+
s.post_install_message = %q{Please run PgAuditLog::Function.install (in console/migration) to install the new versions of the database functions}
|
14
15
|
|
15
16
|
s.files = `git ls-files`.split("\n")
|
16
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/spec/triggers_spec.rb
CHANGED
@@ -110,6 +110,8 @@ describe PgAuditLog::Triggers do
|
|
110
110
|
end
|
111
111
|
|
112
112
|
it "should not fire the audit" do
|
113
|
+
PgAuditLog::Function.install
|
114
|
+
|
113
115
|
PgAuditLog::Triggers.disable
|
114
116
|
expect {
|
115
117
|
TableWithTriggers.create!
|
@@ -117,6 +119,21 @@ describe PgAuditLog::Triggers do
|
|
117
119
|
end
|
118
120
|
end
|
119
121
|
|
122
|
+
describe ".without_triggers" do
|
123
|
+
it "should record the user correctly afterwards" do
|
124
|
+
PgAuditLog::Triggers.without_triggers do
|
125
|
+
expect {
|
126
|
+
TableWithTriggers.create!
|
127
|
+
}.to_not change(PgAuditLog::Entry, :count)
|
128
|
+
end
|
129
|
+
|
130
|
+
expect {
|
131
|
+
TableWithTriggers.create!
|
132
|
+
}.to change(PgAuditLog::Entry, :count)
|
133
|
+
PgAuditLog::Entry.last.user_id.should == -1
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
120
137
|
describe ".create_for_table" do
|
121
138
|
context "for a table that already has a trigger" do
|
122
139
|
it "should not blow up" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_audit_log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -130,7 +130,8 @@ files:
|
|
130
130
|
- spec/triggers_spec.rb
|
131
131
|
homepage: https://github.com/Casecommons/pg_audit_log
|
132
132
|
licenses: []
|
133
|
-
post_install_message:
|
133
|
+
post_install_message: Please run PgAuditLog::Function.install (in console/migration)
|
134
|
+
to install the new versions of the database functions
|
134
135
|
rdoc_options: []
|
135
136
|
require_paths:
|
136
137
|
- lib
|
@@ -142,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
142
143
|
version: '0'
|
143
144
|
segments:
|
144
145
|
- 0
|
145
|
-
hash:
|
146
|
+
hash: 3807464180291971898
|
146
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
148
|
none: false
|
148
149
|
requirements:
|
@@ -151,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
152
|
version: '0'
|
152
153
|
segments:
|
153
154
|
- 0
|
154
|
-
hash:
|
155
|
+
hash: 3807464180291971898
|
155
156
|
requirements: []
|
156
157
|
rubyforge_project:
|
157
158
|
rubygems_version: 1.8.19
|