summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsimon <simon@zagal.(none)>2009-02-09 21:55:02 +0100
committerhukl <hukl@eight.local>2009-02-15 20:22:07 +0100
commitbed876819207e3ae84a285470b39544c2850f38b (patch)
tree1ddd43697228ee6457bec9ca6cece62a602a74de
parent654f1542cafb3a8fc6bcd559952ae1a14c825fc9 (diff)
* here comes da wicked sick auditing observer hack
-rw-r--r--app/controllers/nodes_controller.rb1
-rw-r--r--app/controllers/pages_controller.rb2
-rw-r--r--app/models/auditing_observer.rb8
-rw-r--r--config/environment.rb1
-rw-r--r--lib/auditing.rb26
-rw-r--r--test/fixtures/users.yml4
6 files changed, 39 insertions, 3 deletions
diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb
index 1baf052..34394df 100644
--- a/app/controllers/nodes_controller.rb
+++ b/app/controllers/nodes_controller.rb
@@ -1,4 +1,5 @@
1class NodesController < ApplicationController 1class NodesController < ApplicationController
2 include Auditing
2 3
3 layout 'admin' 4 layout 'admin'
4 5
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb
index 7e3f955..363d1e1 100644
--- a/app/controllers/pages_controller.rb
+++ b/app/controllers/pages_controller.rb
@@ -1,4 +1,6 @@
1class PagesController < ApplicationController 1class PagesController < ApplicationController
2 include Auditing
3
2 # GET /pages 4 # GET /pages
3 # GET /pages.xml 5 # GET /pages.xml
4 def index 6 def index
diff --git a/app/models/auditing_observer.rb b/app/models/auditing_observer.rb
new file mode 100644
index 0000000..acce18c
--- /dev/null
+++ b/app/models/auditing_observer.rb
@@ -0,0 +1,8 @@
1class AuditingObserver < Auditing::Observer
2 observe :node, :page
3
4 # TODO: Insert super secure auditing here
5 def before_save(record)
6 RAILS_DEFAULT_LOGGER.debug ">>>>>>>>>>>>> #{controller.inspect}"
7 end
8end
diff --git a/config/environment.rb b/config/environment.rb
index aad0815..4577575 100644
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -30,6 +30,7 @@ Rails::Initializer.run do |config|
30 30
31 # Activate observers that should always be running 31 # Activate observers that should always be running
32 # config.active_record.observers = :cacher, :garbage_collector, :forum_observer 32 # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
33 config.active_record.observers = :auditing_observer
33 34
34 # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 35 # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
35 # Run "rake -D time" for a list of tasks for finding time zone names. 36 # Run "rake -D time" for a list of tasks for finding time zone names.
diff --git a/lib/auditing.rb b/lib/auditing.rb
new file mode 100644
index 0000000..5379148
--- /dev/null
+++ b/lib/auditing.rb
@@ -0,0 +1,26 @@
1 module Auditing
2 def self.included(base)
3 ActiveRecord::Base.observers.each do |observer|
4 observer = if observer.respond_to?(:to_sym)
5 observer.to_s.camelize.constantize.instance
6 elsif observer.respond_to?(:instance)
7 observer.instance
8 else
9 raise ArgumentError, "#{observer} is an invalid class name"
10 end
11 base.around_filter(observer) if observer.is_a?(Auditing::Observer)
12 end
13 end
14
15 class Observer < ActiveRecord::Observer
16 attr_accessor :controller
17
18 def before(controller)
19 self.controller = controller
20 end
21
22 def after(controller)
23 self.controller = nil
24 end
25 end
26end \ No newline at end of file
diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml
index a6570e0..3afb3fd 100644
--- a/test/fixtures/users.yml
+++ b/test/fixtures/users.yml
@@ -13,6 +13,4 @@ aaron:
13 email: aaron@example.com 13 email: aaron@example.com
14 salt: 5be6f9cdd04fd7ab3c91cd32a5334ba2339b8005 14 salt: 5be6f9cdd04fd7ab3c91cd32a5334ba2339b8005
15 crypted_password: 740a48caf7dd5ff11318d812d57c0a0928cfbc12 # 'monkey' 15 crypted_password: 740a48caf7dd5ff11318d812d57c0a0928cfbc12 # 'monkey'
16 created_at: <%= 1.days.ago.to_s :db %> 16 created_at: <%= 1.days.ago.to_s :db %> \ No newline at end of file
17
18