Browse Source

audit

pull/1/head
Claudius Nicolae 12 years ago
parent
commit
e067486581
  1. 1
      Gemfile
  2. 5
      Gemfile.lock
  3. 3
      app/models/domain.rb
  4. 1
      app/models/permission.rb
  5. 1
      app/models/record.rb
  6. 4
      app/models/user.rb
  7. 3
      config/initializers/rails_admin.rb
  8. 28
      db/migrate/20130305075639_install_audited.rb

1
Gemfile

@ -36,6 +36,7 @@ gem 'seedbank', '~> 0.1.3'
gem 'rails_admin', '~> 0.0.5'
gem 'rails-settings-cached', '~> 0.2.2'
gem 'unicorn', '~> 4.5.0'
gem "audited-activerecord", '~> 3.0'
# Gems used only for assets and not required
# in production environments by default.

5
Gemfile.lock

@ -56,6 +56,10 @@ GEM
acts_as_nested_interval (0.0.10)
rails (~> 3.2.1)
arel (3.0.2)
audited (3.0.0)
audited-activerecord (3.0.0)
activerecord (~> 3.0)
audited (= 3.0.0)
bbenezech-nested_form (0.0.6)
bcrypt-ruby (3.0.1)
bootstrap-sass (2.1.0.1)
@ -333,6 +337,7 @@ DEPENDENCIES
active-model-email-validator (~> 1.0.2)
active_scaffold (~> 3.2.16)
acts_as_nested_interval (~> 0.0.7)
audited-activerecord (~> 3.0)
bootstrap-sass (~> 2.1.0.0)
cancan (= 1.6.7)
capistrano (~> 2.9.0)

3
app/models/domain.rb

@ -2,11 +2,14 @@ class Domain < ActiveRecord::Base
self.inheritance_column = :sti_disabled
nilify_blanks
stampable
audited
# optional IP for create form, results in a type A record
attr_accessor :ip
attr_accessor :domain_ownership_failed
attr_accessible :name, :ip, :soa_record, :ns_records, :apply_subdomains
belongs_to :user, :inverse_of => :domain
has_many :records, :inverse_of => :domain, :dependent => :destroy
has_many :permissions, :inverse_of => :domain, :dependent => :destroy

1
app/models/permission.rb

@ -1,5 +1,6 @@
class Permission < ActiveRecord::Base
stampable
audited
belongs_to :domain, :inverse_of => :permissions
belongs_to :user, :inverse_of => :permissions

1
app/models/record.rb

@ -1,5 +1,6 @@
class Record < ActiveRecord::Base
stampable
audited
belongs_to :domain, :inverse_of => :records
belongs_to :user, :inverse_of => :records

4
app/models/user.rb

@ -2,6 +2,7 @@ class User < ActiveRecord::Base
include SentientModel
model_stamper
stampable
audited
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :timeoutable and :omniauthable
@ -17,7 +18,8 @@ class User < ActiveRecord::Base
validates :first_name, :last_name, :presence => true
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :first_name, :last_name
attr_accessible :email, :password, :password_confirmation, :remember_me,
:first_name, :last_name
has_many :domains, :inverse_of => :user, :dependent => :destroy
has_many :records, :inverse_of => :user, :dependent => :destroy

3
config/initializers/rails_admin.rb

@ -34,7 +34,8 @@ RailsAdmin.config do |config|
# config.excluded_models = [A, AAAA, Admin, CNAME, Domain, MX, NS, Permission, Record, SOA, SRV, TXT, User]
# Add models here if you want to go 'whitelist mode':
# config.included_models = [A, AAAA, Admin, CNAME, Domain, MX, NS, Permission, Record, SOA, SRV, TXT, User]
config.included_models = [A, AAAA, Admin, CNAME, Domain, MX, NS, Permission,
Record, SOA, SRV, TXT, User, Audited::Adapters::ActiveRecord::Audit]
# Application wide tried label methods for models' instances
# config.label_methods << :description # Default is [:name, :title]

28
db/migrate/20130305075639_install_audited.rb

@ -0,0 +1,28 @@
class InstallAudited < ActiveRecord::Migration
def self.up
create_table :audits, :force => true do |t|
t.column :auditable_id, :integer
t.column :auditable_type, :string
t.column :associated_id, :integer
t.column :associated_type, :string
t.column :user_id, :integer
t.column :user_type, :string
t.column :username, :string
t.column :action, :string
t.column :audited_changes, :text
t.column :version, :integer, :default => 0
t.column :comment, :string
t.column :remote_address, :string
t.column :created_at, :datetime
end
add_index :audits, [:auditable_id, :auditable_type], :name => 'auditable_index'
add_index :audits, [:associated_id, :associated_type], :name => 'associated_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
Loading…
Cancel
Save