Revision 229d7436
Added by Joseph Magen over 10 years ago
app/helpers/audits_helper.rb | ||
---|---|---|
module AuditsHelper
|
||
|
||
MainObjects = %w(Host Hostgroup User Operatingsystem Environment Puppetclass Parameter Architecture ComputeResource ConfigTemplate ComputeProfile ComputeAttribute)
|
||
MainObjects = %w(Host Hostgroup User Operatingsystem Environment Puppetclass Parameter Architecture ComputeResource ConfigTemplate ComputeProfile ComputeAttribute
|
||
Location Organization Domain Subnet SmartProxy AuthSource Image Role Usergroup Bookmark)
|
||
|
||
# lookup the Model representing the numerical id and return its label
|
||
def id_to_label name, change
|
app/models/auth_source.rb | ||
---|---|---|
|
||
class AuthSource < ActiveRecord::Base
|
||
include Authorization
|
||
audited :allow_mass_assignment => true
|
||
before_destroy EnsureNotUsedBy.new(:users)
|
||
has_many :users
|
||
|
app/models/bookmark.rb | ||
---|---|---|
class Bookmark < ActiveRecord::Base
|
||
belongs_to :owner, :polymorphic => true
|
||
attr_accessible :name, :controller, :query, :public
|
||
audited :allow_mass_assignment => true
|
||
|
||
validates :name, :uniqueness => true, :unless => Proc.new{|b| Bookmark.my_bookmarks.where(:name => b.name).empty?}
|
||
validates :name, :query, :presence => true
|
app/models/domain.rb | ||
---|---|---|
class Domain < ActiveRecord::Base
|
||
include Authorization
|
||
include Taxonomix
|
||
audited :allow_mass_assignment => true
|
||
|
||
has_many_hosts
|
||
has_many :hostgroups
|
app/models/image.rb | ||
---|---|---|
class Image < ActiveRecord::Base
|
||
|
||
audited :allow_mass_assignment => true
|
||
|
||
belongs_to :operatingsystem
|
||
belongs_to :compute_resource
|
||
belongs_to :architecture
|
app/models/role.rb | ||
---|---|---|
# Built-in roles
|
||
BUILTIN_DEFAULT_USER = 1
|
||
BUILTIN_ANONYMOUS = 2
|
||
audited :allow_mass_assignment => true
|
||
|
||
scope :givable, lambda { where(:builtin => 0).order(:name) }
|
||
scope :for_current_user, lambda { User.current.admin? ? {} : where(:id => User.current.role_ids) }
|
app/models/smart_proxy.rb | ||
---|---|---|
class SmartProxy < ActiveRecord::Base
|
||
include Authorization
|
||
include Taxonomix
|
||
audited :allow_mass_assignment => true
|
||
|
||
attr_accessible :name, :url, :location_ids, :organization_ids
|
||
EnsureNotUsedBy.new(:hosts, :hostgroups, :subnets, :domains, :puppet_ca_hosts, :puppet_ca_hostgroups)
|
app/models/subnet.rb | ||
---|---|---|
class Subnet < ActiveRecord::Base
|
||
include Authorization
|
||
include Taxonomix
|
||
audited :allow_mass_assignment => true
|
||
|
||
before_destroy EnsureNotUsedBy.new(:hosts, :interfaces )
|
||
has_many_hosts
|
app/models/usergroup.rb | ||
---|---|---|
class Usergroup < ActiveRecord::Base
|
||
include Authorization
|
||
audited :allow_mass_assignment => true
|
||
|
||
has_many :usergroup_members, :dependent => :destroy
|
||
has_many :users, :through => :usergroup_members, :source => :member, :source_type => 'User'
|
db/seeds.rb | ||
---|---|---|
end
|
||
|
||
# Bookmarks
|
||
[
|
||
{ :name => "eventful", :query => "eventful = true", :controller=> "reports" },
|
||
{ :name => "active", :query => 'last_report > "35 minutes ago" and (status.applied > 0 or status.restarted > 0)', :controller=> "hosts" },
|
||
{ :name => "out of sync", :query => 'last_report < "30 minutes ago" andstatus.enabled = true', :controller=> "hosts" },
|
||
{ :name => "error", :query => 'last_report > "35 minutes ago" and (status.failed > 0 or status.failed_restarts > 0 or status.skipped > 0)', :controller=> "hosts" },
|
||
{ :name => "disabled", :query => 'status.enabled = false', :controller=> "hosts" },
|
||
{ :name => "ok hosts", :query => 'last_report > "35 minutes ago" and status.enabled = true and status.applied = 0 and status.failed = 0 and status.pending = 0', :controller=> "hosts" }
|
||
].each do |input|
|
||
next if Bookmark.find_by_name(input[:name])
|
||
next if audit_modified? Bookmark, input[:name]
|
||
b = Bookmark.create({ :public => true }.merge(input))
|
||
raise "Unable to create bookmark: #{format_errors b}" if b.nil? || b.errors.any?
|
||
Bookmark.without_auditing do
|
||
[
|
||
{ :name => "eventful", :query => "eventful = true", :controller=> "reports" },
|
||
{ :name => "active", :query => 'last_report > "35 minutes ago" and (status.applied > 0 or status.restarted > 0)', :controller=> "hosts" },
|
||
{ :name => "out of sync", :query => 'last_report < "30 minutes ago" andstatus.enabled = true', :controller=> "hosts" },
|
||
{ :name => "error", :query => 'last_report > "35 minutes ago" and (status.failed > 0 or status.failed_restarts > 0 or status.skipped > 0)', :controller=> "hosts" },
|
||
{ :name => "disabled", :query => 'status.enabled = false', :controller=> "hosts" },
|
||
{ :name => "ok hosts", :query => 'last_report > "35 minutes ago" and status.enabled = true and status.applied = 0 and status.failed = 0 and status.pending = 0', :controller=> "hosts" }
|
||
].each do |input|
|
||
next if Bookmark.find_by_name(input[:name])
|
||
next if audit_modified? Bookmark, input[:name]
|
||
b = Bookmark.create({ :public => true }.merge(input))
|
||
raise "Unable to create bookmark: #{format_errors b}" if b.nil? || b.errors.any?
|
||
end
|
||
end
|
||
|
||
# Proxy features
|
||
... | ... | |
raise "Unable to create proxy feature: #{format_errors f}" if f.nil? || f.errors.any?
|
||
end
|
||
|
||
# Auth sources
|
||
src = AuthSourceInternal.find_by_type "AuthSourceInternal"
|
||
src ||= AuthSourceInternal.create :name => "Internal"
|
||
AuthSource.without_auditing do
|
||
# Auth sources
|
||
src = AuthSourceInternal.find_by_type "AuthSourceInternal"
|
||
src ||= AuthSourceInternal.create :name => "Internal"
|
||
|
||
# Users
|
||
unless User.find_by_login("admin").present?
|
||
User.without_auditing do
|
||
user = User.new(:login => "admin", :firstname => "Admin", :lastname => "User", :mail => Setting[:administrator])
|
||
user.admin = true
|
||
user.auth_source = src
|
||
user.password = "changeme"
|
||
User.current = user
|
||
raise "Unable to create admin user: #{format_errors user}" unless user.save
|
||
# Users
|
||
unless User.find_by_login("admin").present?
|
||
User.without_auditing do
|
||
user = User.new(:login => "admin", :firstname => "Admin", :lastname => "User", :mail => Setting[:administrator])
|
||
user.admin = true
|
||
user.auth_source = src
|
||
user.password = "changeme"
|
||
User.current = user
|
||
raise "Unable to create admin user: #{format_errors user}" unless user.save
|
||
end
|
||
end
|
||
end
|
||
|
Also available in: Unified diff
fixes #3975 - add audit to classes Domain, Subnet, SmartProxy, Role, Usergroup, AuthSource, Image, Bookmark that were not audited