This repository has been archived by the owner on Apr 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,23 @@ | |||
class AddAuditsTable < ActiveRecord::Migration | |||
def self.up | |||
create_table :audits, :force => true do |t| | |||
t.column :auditable_id, :integer | |||
t.column :auditable_type, :string | |||
t.column :user_id, :integer | |||
t.column :user_type, :string | |||
t.column :username, :string | |||
t.column :action, :string | |||
t.column :changes, :text | |||
t.column :version, :integer, :default => 0 | |||
t.column :created_at, :datetime | |||
end | |||
|
|||
add_index :audits, [:auditable_id, :auditable_type], :name => 'auditable_index' | |||
add_index :audits, [:user_id, :user_type], :name => 'user_index' | |||
add_index :audits, :created_at | |||
end | |||
|
|||
def self.down | |||
drop_table :audits | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
acts_as_audited_plugin.sqlite3.db | |||
test/debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,22 @@ | |||
acts_as_audited ChangeLog | |||
------------------------------------------------------------------------------- | |||
* 2008-04-19 - refactored to make compatible with dirty tracking in edge rails | |||
and to stop storing both old and new values in a single audit | |||
* 2008-04-18 - Fix NoMethodError when trying to access the :previous revision | |||
on a model that doesn't have previous revisions [Alex Soto] | |||
* 2008-03-21 - added #changed_attributes to get access to the changes before a | |||
save [Chris Parker] | |||
* 2007-12-16 - Added #revision_at for retrieving a revision from a specific | |||
time [Jacob Atzen] | |||
* 2007-12-16 - Fix error when getting revision from audit with no changes | |||
[Geoffrey Wiseman] | |||
* 2007-12-16 - Remove dependency on acts_as_list | |||
* 2007-06-17 - Added support getting previous revisions | |||
* 2006-11-17 - Replaced use of singleton User.current_user with cache sweeper | |||
implementation for auditing the user that made the change | |||
* 2006-11-17 - added migration generator | |||
* 2006-08-14 - incorporated changes from Michael Schuerig to write_attribute | |||
that saves the new value after every change and not just the | |||
first, and performs proper type-casting before doing comparisons | |||
* 2006-08-14 - The "changes" are now saved as a serialized hash | |||
* 2006-07-21 - initial version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,67 @@ | |||
= acts_as_audited | |||
|
|||
acts_as_audited is an ActiveRecord extension that logs all changes to your models in an audits table. | |||
|
|||
== Installation | |||
|
|||
* Install the plugin into your rails app | |||
If you are using Rails 2.1: | |||
|
|||
script/plugin install git://github.com/collectiveidea/acts_as_audited.git | |||
|
|||
For versions prior to 2.1: | |||
|
|||
git clone git://github.com/collectiveidea/acts_as_audited.git vendor/plugins/acts_as_audited | |||
|
|||
* Generate the migration | |||
script/generate audited_migration add_audits_table | |||
rake db:migrate | |||
|
|||
== Auditing in Rails | |||
|
|||
If you're using acts_as_audited within Rails, you can simply declare which models should be audited. acts_as_audited can also automatically record the user that made the change if your controller has a <tt>current_user</tt> method. | |||
|
|||
class ApplicationController < ActionController::Base | |||
audit User, List, Item | |||
protected | |||
def current_user | |||
@user ||= User.find(session[:user]) | |||
end | |||
end | |||
|
|||
== Customizing | |||
|
|||
To get auditing outside of Rails, or to customize which fields are audited within Rails, you can explicitly declare <tt>acts_as_audited</tt> on your models: | |||
|
|||
class User < ActiveRecord::Base | |||
acts_as_audited :except => [:password, :mistress] | |||
end | |||
|
|||
See http://opensoul.org/2006/07/21/acts_as_audited for more information. | |||
|
|||
== Caveats | |||
|
|||
Auditing with user support depends on Rails' caching mechanisms, therefore auditing isn't enabled during development mode. To test that auditing is working, start up your app in production mode, or change the following options in config/environments/environment.rb: | |||
|
|||
config.cache_classes = true | |||
config.action_controller.perform_caching = true | |||
|
|||
=== ActiveScaffold | |||
|
|||
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: | |||
|
|||
class ApplicationController < ActionController::Base | |||
audit MyModel, :only => [:create, :update, :destroy] | |||
end | |||
|
|||
== Upgrading | |||
|
|||
To upgrade from an older version, add a migration with: | |||
|
|||
# to version 0.3 | |||
add_column :audits, :user_type, :string | |||
add_column :audits, :username, :string | |||
|
|||
# to version 0.4 | |||
add_column :audits, :version, :integer, :default => 0 | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,28 @@ | |||
require 'rake' | |||
require 'rake/testtask' | |||
require 'rake/rdoctask' | |||
|
|||
desc 'Default: run unit tests.' | |||
task :default => :test | |||
|
|||
desc 'Test the acts_as_audited plugin' | |||
Rake::TestTask.new(:test) do |t| | |||
t.libs << 'lib' | |||
t.pattern = 'test/**/*_test.rb' | |||
t.verbose = true | |||
end | |||
|
|||
desc 'Generate documentation for the acts_as_audited plugin.' | |||
Rake::RDocTask.new(:rdoc) do |rdoc| | |||
rdoc.rdoc_dir = 'doc' | |||
rdoc.title = 'acts_as_audited' | |||
rdoc.options << '--line-numbers' << '--inline-source' | |||
rdoc.rdoc_files.include('README') | |||
rdoc.rdoc_files.include('lib/**/*.rb') | |||
end | |||
|
|||
desc "Publish the rdocs" | |||
task :publish => [:rdoc] do | |||
`ssh host.collectiveidea.com "mkdir -p /var/www/vhosts/source.collectiveidea.com/public/dist/api/acts_as_audited"` | |||
Rake::SshDirPublisher.new("host.collectiveidea.com", "/var/www/vhosts/source.collectiveidea.com/public/dist/api/acts_as_audited", "doc").upload | |||
end |
7 changes: 7 additions & 0 deletions
7
vendor/plugins/acts_as_audited/generators/audited_migration/USAGE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
Description: | |||
The audited migration generator creates a migration to add the audits table. | |||
|
|||
Example: | |||
./script/generate audited_migration add_audits_table | |||
|
|||
This will create a migration in db/migrate/. Run "rake db:migrate" to update your database. |
7 changes: 7 additions & 0 deletions
7
vendor/plugins/acts_as_audited/generators/audited_migration/audited_migration_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
class AuditedMigrationGenerator < Rails::Generator::NamedBase | |||
def manifest | |||
record do |m| | |||
m.migration_template 'migration.rb', 'db/migrate' | |||
end | |||
end | |||
end |
23 changes: 23 additions & 0 deletions
23
vendor/plugins/acts_as_audited/generators/audited_migration/templates/migration.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,23 @@ | |||
class <%= class_name %> < ActiveRecord::Migration | |||
def self.up | |||
create_table :audits, :force => true do |t| | |||
t.column :auditable_id, :integer | |||
t.column :auditable_type, :string | |||
t.column :user_id, :integer | |||
t.column :user_type, :string | |||
t.column :username, :string | |||
t.column :action, :string | |||
t.column :changes, :text | |||
t.column :version, :integer, :default => 0 | |||
t.column :created_at, :datetime | |||
end | |||
|
|||
add_index :audits, [:auditable_id, :auditable_type], :name => 'auditable_index' | |||
add_index :audits, [:user_id, :user_type], :name => 'user_index' | |||
add_index :audits, :created_at | |||
end | |||
|
|||
def self.down | |||
drop_table :audits | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
require 'acts_as_audited/audit' | |||
require 'acts_as_audited' | |||
|
|||
ActiveRecord::Base.send :include, CollectiveIdea::Acts::Audited | |||
|
|||
if defined?(ActionController) and defined?(ActionController::Base) | |||
require 'acts_as_audited/audit_sweeper' | |||
ActionController::Base.send :include, CollectiveIdea::ActionController::Audited | |||
end |
Oops, something went wrong.