yoon-view_trail 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.md +49 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/generators/view_trail/templates/create_activities.rb +17 -0
- data/generators/view_trail/view_trail_generator.rb +9 -0
- data/lib/view_trail/activity.rb +3 -0
- data/lib/view_trail.rb +53 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/view_trail_spec.rb +7 -0
- data/view_trail.gemspec +50 -0
- metadata +67 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Mark Yoon
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# ViewTrail
|
2
|
+
|
3
|
+
ViewTrail lets you track controllers and views that you select for auditing. You can see who look at what (controller/action/params hash) and when.
|
4
|
+
|
5
|
+
## Rails Version
|
6
|
+
|
7
|
+
Works with Rails 2.3.
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
class FooController < ActionController::Base
|
12
|
+
has_view_trail :except => :index
|
13
|
+
end
|
14
|
+
|
15
|
+
Takes :except and :only conditions like other controller filters
|
16
|
+
|
17
|
+
>> Activities.last.whodunnit
|
18
|
+
>> Activities.last.created_at
|
19
|
+
>> Activities.last.controller
|
20
|
+
>> Activities.last.action
|
21
|
+
>> Activities.last.params
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
1. Install ViewTrail as a gem:
|
26
|
+
|
27
|
+
`config.gem 'yoon-view_trail', :lib => 'view_trail', :source => 'http://gems.github.com'`
|
28
|
+
|
29
|
+
2. Create a migration for the `versions` table
|
30
|
+
|
31
|
+
`script/generate view_trail`
|
32
|
+
|
33
|
+
3. Run the migration.
|
34
|
+
|
35
|
+
`rake db:migrate`
|
36
|
+
|
37
|
+
4. Add `has view_trail` to the controllers you want to track
|
38
|
+
|
39
|
+
## TODO
|
40
|
+
|
41
|
+
Test!
|
42
|
+
|
43
|
+
## Inspiration
|
44
|
+
|
45
|
+
* [PaperTrail](http://github.com/airblade/paper_trail/)
|
46
|
+
|
47
|
+
## Intellectual Property
|
48
|
+
|
49
|
+
Copyright (c) 2009 Mark Yoon. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "view_trail"
|
8
|
+
gem.summary = %Q{View trail tracks controller actions in Rails.}
|
9
|
+
gem.description = %Q{View trail tracks controller actions in Rails.}
|
10
|
+
gem.email = "yoon@northwestern.edu"
|
11
|
+
gem.homepage = "http://github.com/yoon/view_trail"
|
12
|
+
gem.authors = ["Mark Yoon"]
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'spec/rake/spectask'
|
21
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
22
|
+
spec.libs << 'lib' << 'spec'
|
23
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
24
|
+
end
|
25
|
+
|
26
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
27
|
+
spec.libs << 'lib' << 'spec'
|
28
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
29
|
+
spec.rcov = true
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
task :default => :spec
|
34
|
+
|
35
|
+
require 'rake/rdoctask'
|
36
|
+
Rake::RDocTask.new do |rdoc|
|
37
|
+
if File.exist?('VERSION.yml')
|
38
|
+
config = YAML.load(File.read('VERSION.yml'))
|
39
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
40
|
+
else
|
41
|
+
version = ""
|
42
|
+
end
|
43
|
+
|
44
|
+
rdoc.rdoc_dir = 'rdoc'
|
45
|
+
rdoc.title = "view_trail #{version}"
|
46
|
+
rdoc.rdoc_files.include('README*')
|
47
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
48
|
+
end
|
49
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateActivities < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :activities do |t|
|
4
|
+
t.string :controller
|
5
|
+
t.string :action
|
6
|
+
t.text :params
|
7
|
+
t.string :whodunnit
|
8
|
+
t.datetime :created_at
|
9
|
+
end
|
10
|
+
# add_index :activities, [:item_type, :item_id]
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
# remove_index :activities, [:item_type, :item_id]
|
15
|
+
drop_table :activities
|
16
|
+
end
|
17
|
+
end
|
data/lib/view_trail.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'view_trail/activity'
|
2
|
+
|
3
|
+
module ViewTrail
|
4
|
+
@@whodunnit = nil
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.send :extend, ClassMethods
|
8
|
+
base.before_filter :set_whodunnit
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.whodunnit
|
12
|
+
@@whodunnit.respond_to?(:call) ? @@whodunnit.call : @@whodunnit
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.whodunnit=(value)
|
16
|
+
@@whodunnit = value
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def set_whodunnit
|
22
|
+
@@whodunnit = lambda {
|
23
|
+
self.respond_to?(:current_user) ? self.current_user : nil
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
module ClassMethods
|
28
|
+
def has_view_trail(&block)
|
29
|
+
before_filter :set_whodunnit
|
30
|
+
after_filter(:record_activity, &block)
|
31
|
+
cattr_accessor :view_trail_active
|
32
|
+
self.view_trail_active = true
|
33
|
+
send :include, InstanceMethods
|
34
|
+
end
|
35
|
+
|
36
|
+
def view_trail_off
|
37
|
+
self.view_trail_active = false
|
38
|
+
end
|
39
|
+
def view_trail_on
|
40
|
+
self.view_trail_active = true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module InstanceMethods
|
45
|
+
def record_activity
|
46
|
+
if self.class.view_trail_active
|
47
|
+
Activity.create(:whodunnit => ViewTrail.whodunnit, :controller => params.delete(:controller), :action => params.delete(:action), :params => params.inspect)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
ActionController::Base.send :include, ViewTrail
|
data/spec/spec_helper.rb
ADDED
data/view_trail.gemspec
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{view_trail}
|
5
|
+
s.version = "0.2.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Mark Yoon"]
|
9
|
+
s.date = %q{2009-07-15}
|
10
|
+
s.description = %q{View trail tracks controller actions in Rails.}
|
11
|
+
s.email = %q{yoon@northwestern.edu}
|
12
|
+
s.extra_rdoc_files = [
|
13
|
+
"LICENSE",
|
14
|
+
"README.md"
|
15
|
+
]
|
16
|
+
s.files = [
|
17
|
+
".document",
|
18
|
+
".gitignore",
|
19
|
+
"LICENSE",
|
20
|
+
"README.md",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"generators/view_trail/templates/create_activities.rb",
|
24
|
+
"generators/view_trail/view_trail_generator.rb",
|
25
|
+
"lib/view_trail.rb",
|
26
|
+
"lib/view_trail/activity.rb",
|
27
|
+
"spec/spec_helper.rb",
|
28
|
+
"spec/view_trail_spec.rb",
|
29
|
+
"view_trail.gemspec"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/yoon/view_trail}
|
32
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = %q{1.3.4}
|
35
|
+
s.summary = %q{View trail tracks controller actions in Rails.}
|
36
|
+
s.test_files = [
|
37
|
+
"spec/spec_helper.rb",
|
38
|
+
"spec/view_trail_spec.rb"
|
39
|
+
]
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
46
|
+
else
|
47
|
+
end
|
48
|
+
else
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yoon-view_trail
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Yoon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-15 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: View trail tracks controller actions in Rails.
|
17
|
+
email: yoon@northwestern.edu
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
files:
|
26
|
+
- .document
|
27
|
+
- .gitignore
|
28
|
+
- LICENSE
|
29
|
+
- README.md
|
30
|
+
- Rakefile
|
31
|
+
- VERSION
|
32
|
+
- generators/view_trail/templates/create_activities.rb
|
33
|
+
- generators/view_trail/view_trail_generator.rb
|
34
|
+
- lib/view_trail.rb
|
35
|
+
- lib/view_trail/activity.rb
|
36
|
+
- spec/spec_helper.rb
|
37
|
+
- spec/view_trail_spec.rb
|
38
|
+
- view_trail.gemspec
|
39
|
+
has_rdoc: false
|
40
|
+
homepage: http://github.com/yoon/view_trail
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options:
|
43
|
+
- --charset=UTF-8
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.2.0
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: View trail tracks controller actions in Rails.
|
65
|
+
test_files:
|
66
|
+
- spec/spec_helper.rb
|
67
|
+
- spec/view_trail_spec.rb
|