Project

General

Profile

« Previous | Next » 

Revision 8a65dff7

Added by Ohad Levy almost 13 years ago

  • ID 8a65dff786359b268b4e5033790092e8c50f40cd

fixes #777 - this enable auditing of when a host is changing its puppet class assignmetns

one limitation of this patch is that at the moment, each class change
gets its own audit record.

View differences:

app/models/host.rb
belongs_to :model
belongs_to :domain
belongs_to :operatingsystem
has_and_belongs_to_many :puppetclasses
has_many :host_classes, :dependent => :destroy
has_many :puppetclasses, :through => :host_classes
belongs_to :environment
belongs_to :subnet
belongs_to :ptable
app/models/host_class.rb
class HostClass < ActiveRecord::Base
acts_as_audited :parent => :host
belongs_to :host
belongs_to :puppetclass
validates_presence_of :host_id, :puppetclass_id
def name
"#{host} - #{puppetclass}"
end
end
app/models/puppetclass.rb
include Authorization
has_and_belongs_to_many :environments
has_and_belongs_to_many :operatingsystems
has_and_belongs_to_many :hosts
has_and_belongs_to_many :hostgroups
has_many :host_classes, :dependent => :destroy
has_many :hosts, :through => :host_classes
has_many :lookup_keys, :inverse_of => :puppetclass
accepts_nested_attributes_for :lookup_keys, :reject_if => lambda { |a| a[:key].blank? }, :allow_destroy => true
config/initializers/foreman.rb
require 'access_permissions'
require 'puppet'
require 'puppet/rails'
require 'core_extensions'
# import settings file
SETTINGS= YAML.load_file("#{RAILS_ROOT}/config/settings.yaml")
db/migrate/20110712064120_update_audits_table.rb
class UpdateAuditsTable < ActiveRecord::Migration
def self.up
add_column :audits, :comment, :string
add_column :audits, :auditable_parent_id, :integer
add_column :audits, :auditable_parent_type, :string
add_index :audits, [:auditable_parent_id, :auditable_parent_type], :name => 'auditable_parent_index'
end
def self.down
remove_column :audits, :comment
remove_column :audits, :auditable_parent_id
remove_column :audits, :auditable_parent_type
end
end
db/migrate/20110712070522_create_host_class.rb
class CreateHostClass < ActiveRecord::Migration
def self.up
rename_table :hosts_puppetclasses, :host_classes
add_column :host_classes, :id, :primary_key
end
def self.down
remove_column :host_classes, :id
rename_table :host_classes, :hosts_puppetclasses
end
end
lib/core_extensions.rb
ActiveRecord::Associations::HasManyThroughAssociation.class_eval do
def delete_records(records)
klass = @reflection.through_reflection.klass
records.each do |associate|
klass.destroy_all(construct_join_attributes(associate))
end
end
end
test/fixtures/host_classes.yml
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one:
host: one
puppetclass: one
test/unit/host_class_test.rb
require 'test_helper'
class HostClassTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
vendor/plugins/acts_as_audited
Subproject commit 6550a3896c196b07f7d2b39dcda0c53d4462e5af
Subproject commit de6031feaf1e5d999f70265944d76758fc85b477

Also available in: Unified diff