acts_as_audited 1.0.2 → 1.1.0
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.
- data/README +10 -23
- data/VERSION +1 -1
- data/acts_as_audited.gemspec +2 -2
- data/lib/acts_as_audited/audit_sweeper.rb +19 -48
- data/lib/acts_as_audited.rb +3 -27
- data/rails/init.rb +0 -1
- data/test/acts_as_audited_test.rb +0 -9
- data/test/audit_sweeper_test.rb +0 -8
- metadata +2 -2
data/README
CHANGED
@@ -21,30 +21,20 @@ The purpose of this fork is to store both the previous values and the changed va
|
|
21
21
|
|
22
22
|
== Usage
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
class ApplicationController < ActionController::Base
|
27
|
-
audit User, List, Item => {:except => :password}
|
28
|
-
protected
|
29
|
-
def current_user
|
30
|
-
@user ||= User.find(session[:user])
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
To get auditing outside of Rails you can explicitly declare <tt>acts_as_audited</tt> on your models:
|
24
|
+
Declare <tt>acts_as_audited</tt> on your models:
|
35
25
|
|
36
26
|
class User < ActiveRecord::Base
|
37
27
|
acts_as_audited :except => [:password, :mistress]
|
38
28
|
end
|
29
|
+
|
30
|
+
Within a web request, will automatically record the user that made the change if your controller has a <tt>current_user</tt> method.
|
39
31
|
|
40
|
-
To record a user in the audits
|
32
|
+
To record a user in the audits outside of a web request, you can use <tt>as_user</tt>:
|
41
33
|
|
42
|
-
Audit.as_user(
|
34
|
+
Audit.as_user(user) do
|
43
35
|
# Perform changes on audited models
|
44
36
|
end
|
45
37
|
|
46
|
-
See http://opensoul.org/2006/07/21/acts_as_audited for more information.
|
47
|
-
|
48
38
|
== Caveats
|
49
39
|
|
50
40
|
If your model declares +attr_accessible+ after +acts_as_audited+, you need to set +:protect+ to false. acts_as_audited uses +attr_protected+ internally to prevent malicious users from unassociating your audits, and Rails does not allow both +attr_protected+ and +attr_accessible+. It will default to false if +attr_accessible+ is called before +acts_as_audited+, but needs to be explicitly set if it is called after.
|
@@ -54,18 +44,15 @@ If your model declares +attr_accessible+ after +acts_as_audited+, you need to se
|
|
54
44
|
attr_accessible :name
|
55
45
|
end
|
56
46
|
|
57
|
-
=== ActiveScaffold
|
58
|
-
|
59
|
-
Many users have also reported problems with acts_as_audited and ActiveScaffold, which appears to be caused by a limitation in ActiveScaffold not supporting polymorphic associations. To get it to work with ActiveScaffold:
|
60
|
-
|
61
|
-
class ApplicationController < ActionController::Base
|
62
|
-
audit MyModel, :only => [:create, :update, :destroy]
|
63
|
-
end
|
64
|
-
|
65
47
|
== Compatability
|
66
48
|
|
67
49
|
acts_as_audited works with Rails 2.1 or later.
|
68
50
|
|
51
|
+
== Getting Help
|
52
|
+
|
53
|
+
Join the mailing list for getting help or offering suggestions:
|
54
|
+
http://groups.google.com/group/acts_as_audited
|
55
|
+
|
69
56
|
== Contributing
|
70
57
|
|
71
58
|
Contributions are always welcome. Checkout the latest code on GitHub:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
data/acts_as_audited.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{acts_as_audited}
|
8
|
-
s.version = "1.0
|
8
|
+
s.version = "1.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brandon Keepers"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-11-01}
|
13
13
|
s.email = %q{brandon@opensoul.org}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
@@ -1,65 +1,36 @@
|
|
1
|
-
|
2
1
|
module CollectiveIdea #:nodoc:
|
3
2
|
module ActionController #:nodoc:
|
4
3
|
module Audited #:nodoc:
|
4
|
+
def audit(*models)
|
5
|
+
ActiveSupport::Deprecation.warn("#audit is deprecated. Declare #acts_as_audited in your models.", caller)
|
6
|
+
|
7
|
+
options = models.extract_options!
|
8
|
+
|
9
|
+
# Parse the options hash looking for classes
|
10
|
+
options.each_key do |key|
|
11
|
+
models << [key, options.delete(key)] if key.is_a?(Class)
|
12
|
+
end
|
5
13
|
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
|
10
|
-
module ClassMethods
|
11
|
-
# Declare models that should be audited in your controller
|
12
|
-
#
|
13
|
-
# class ApplicationController < ActionController::Base
|
14
|
-
# audit User, Widget
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# You can optionally pass options for each model to be audited:
|
18
|
-
#
|
19
|
-
# audit User, Widget, Task => { :except => :position }
|
20
|
-
#
|
21
|
-
# NOTE: Models which do not have options must be listed first in the
|
22
|
-
# call to <tt>audit</tt>.
|
23
|
-
#
|
24
|
-
# See <tt>CollectiveIdea::Acts::Audited::ClassMethods#acts_as_audited</tt>
|
25
|
-
# for configuration options
|
26
|
-
#
|
27
|
-
# You can also specify an options hash which will be passed on to
|
28
|
-
# Rails' cache_sweeper call:
|
29
|
-
#
|
30
|
-
# audit User, :only => [:create, :edit, :destroy],
|
31
|
-
#
|
32
|
-
def audit(*models)
|
33
|
-
options = models.extract_options!
|
34
|
-
|
35
|
-
# Parse the options hash looking for classes
|
36
|
-
options.each_key do |key|
|
37
|
-
models << [key, options.delete(key)] if key.is_a?(Class)
|
38
|
-
end
|
39
|
-
|
40
|
-
models.each do |(model, model_options)|
|
41
|
-
model.send :acts_as_audited, model_options || {}
|
42
|
-
end
|
43
|
-
|
44
|
-
class_eval do
|
45
|
-
# prevent observer from being registered multiple times
|
46
|
-
Audit.delete_observer(AuditSweeper.instance)
|
47
|
-
Audit.add_observer(AuditSweeper.instance)
|
48
|
-
cache_sweeper :audit_sweeper, options
|
49
|
-
end
|
14
|
+
models.each do |(model, model_options)|
|
15
|
+
model.send :acts_as_audited, model_options || {}
|
50
16
|
end
|
51
17
|
end
|
52
|
-
|
53
18
|
end
|
54
19
|
end
|
55
20
|
end
|
56
21
|
|
57
22
|
class AuditSweeper < ActionController::Caching::Sweeper #:nodoc:
|
58
|
-
def before_create(
|
59
|
-
|
23
|
+
def before_create(audit)
|
24
|
+
audit.user ||= current_user
|
60
25
|
end
|
61
26
|
|
62
27
|
def current_user
|
63
28
|
controller.send :current_user if controller.respond_to?(:current_user, true)
|
64
29
|
end
|
65
30
|
end
|
31
|
+
|
32
|
+
ActionController::Base.class_eval do
|
33
|
+
extend CollectiveIdea::ActionController::Audited
|
34
|
+
cache_sweeper :audit_sweeper
|
35
|
+
end
|
36
|
+
Audit.add_observer(AuditSweeper.instance)
|
data/lib/acts_as_audited.rb
CHANGED
@@ -82,9 +82,9 @@ module CollectiveIdea #:nodoc:
|
|
82
82
|
attr_protected :audit_ids if options[:protect]
|
83
83
|
Audit.audited_class_names << self.to_s
|
84
84
|
|
85
|
-
after_create
|
86
|
-
before_update :
|
87
|
-
after_destroy :
|
85
|
+
after_create :audit_create
|
86
|
+
before_update :audit_update
|
87
|
+
after_destroy :audit_destroy
|
88
88
|
|
89
89
|
attr_accessor :version
|
90
90
|
|
@@ -200,14 +200,6 @@ module CollectiveIdea #:nodoc:
|
|
200
200
|
def write_audit(attrs)
|
201
201
|
self.audits.create attrs if auditing_enabled
|
202
202
|
end
|
203
|
-
|
204
|
-
CALLBACKS.each do |attr_name|
|
205
|
-
alias_method "#{attr_name}_callback".to_sym, attr_name
|
206
|
-
end
|
207
|
-
|
208
|
-
def empty_callback #:nodoc:
|
209
|
-
end
|
210
|
-
|
211
203
|
end # InstanceMethods
|
212
204
|
|
213
205
|
module SingletonMethods
|
@@ -236,22 +228,6 @@ module CollectiveIdea #:nodoc:
|
|
236
228
|
write_inheritable_attribute :auditing_enabled, true
|
237
229
|
end
|
238
230
|
|
239
|
-
def disable_auditing_callbacks
|
240
|
-
class_eval do
|
241
|
-
CALLBACKS.each do |attr_name|
|
242
|
-
alias_method "#{attr_name}_callback", :empty_callback
|
243
|
-
end
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
def enable_auditing_callbacks
|
248
|
-
class_eval do
|
249
|
-
CALLBACKS.each do |attr_name|
|
250
|
-
alias_method "#{attr_name}_callback".to_sym, attr_name
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
231
|
# All audit operations during the block are recorded as being
|
256
232
|
# made by +user+. This is not model specific, the method is a
|
257
233
|
# convenience wrapper around #Audit.as_user.
|
data/rails/init.rb
CHANGED
@@ -295,15 +295,6 @@ module CollectiveIdea
|
|
295
295
|
User.without_auditing { User.create(:name => 'Brandon') }
|
296
296
|
end.should_not change { Audit.count }
|
297
297
|
end
|
298
|
-
|
299
|
-
should "not save an audit when callbacks are disabled" do
|
300
|
-
begin
|
301
|
-
User.disable_auditing_callbacks
|
302
|
-
lambda { create_user }.should_not change { Audit.count }
|
303
|
-
ensure
|
304
|
-
User.enable_auditing_callbacks
|
305
|
-
end
|
306
|
-
end
|
307
298
|
end
|
308
299
|
|
309
300
|
context "attr_protected and attr_accessible" do
|
data/test/audit_sweeper_test.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
2
|
|
3
3
|
class AuditsController < ActionController::Base
|
4
|
-
audit Company, User
|
5
|
-
|
6
4
|
def audit
|
7
5
|
@company = Company.create
|
8
6
|
render :nothing => true
|
@@ -20,11 +18,6 @@ AuditsController.view_paths = [File.dirname(__FILE__)]
|
|
20
18
|
ActionController::Routing::Routes.draw {|m| m.connect ':controller/:action/:id' }
|
21
19
|
|
22
20
|
class AuditsControllerTest < ActionController::TestCase
|
23
|
-
|
24
|
-
should "call acts as audited on non audited models" do
|
25
|
-
Company.should be_kind_of(CollectiveIdea::Acts::Audited::SingletonMethods)
|
26
|
-
end
|
27
|
-
|
28
21
|
should "audit user" do
|
29
22
|
user = @controller.send(:current_user=, create_user)
|
30
23
|
lambda { post :audit }.should change { Audit.count }
|
@@ -35,5 +28,4 @@ class AuditsControllerTest < ActionController::TestCase
|
|
35
28
|
user = @controller.send(:current_user=, create_user)
|
36
29
|
lambda { post :update_user }.should_not change { Audit.count }
|
37
30
|
end
|
38
|
-
|
39
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_audited
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Keepers
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-01 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|