Revision 9c0e127b
Added by Paul Kelly about 14 years ago
- ID 9c0e127b1d42b7243403dd49d739cf8e97baa60b
app/models/host.rb | ||
---|---|---|
has_many :reports, :dependent => :destroy
|
||
has_many :host_parameters, :dependent => :destroy
|
||
accepts_nested_attributes_for :host_parameters, :reject_if => lambda { |a| a[:value].blank? }, :allow_destroy => true
|
||
belongs_to :owner, :polymorphic => true
|
||
|
||
named_scope :recent, lambda { |*args| {:conditions => ["last_report > ?", (args.first || (SETTINGS[:run_interval] + 5.minutes).ago)]} }
|
||
named_scope :out_of_sync, lambda { |*args| {:conditions => ["last_report < ?", (args.first || (SETTINGS[:run_interval] + 5.minutes).ago)]} }
|
||
... | ... | |
|
||
before_validation :normalize_addresses, :normalize_hostname
|
||
|
||
def <=>(other)
|
||
self.name <=> other.name
|
||
end
|
||
|
||
# Returns the name of this host as a string
|
||
# String: the host's name
|
||
def to_label
|
||
... | ... | |
20
|
||
end
|
||
|
||
# method to return the correct owner list for host edit owner select dropbox
|
||
def is_owned_by
|
||
owner.id_and_type if owner
|
||
end
|
||
|
||
# virtual attributes which sets the owner based on the user selection
|
||
# supports a simple user, or a usergroup
|
||
# selection parameter is expected to be an ActiveRecord id_and_type method (see Foreman's AR extentions).
|
||
def is_owned_by=(selection)
|
||
oid = User.find(selection.to_i) if selection =~ /-Users$/
|
||
oid = Usergroup.find(selection.to_i) if selection =~ /-Usergroups$/
|
||
self.owner = oid
|
||
end
|
||
|
||
def clearReports
|
||
# Remove any reports that may be held against this host
|
||
Report.delete_all("host_id = #{self.id}")
|
Also available in: Unified diff
Fixes #170 - implement usergroups
Added migration
Added tests
Added MVC files
Added the routes as well
Added the program logic and additional views
Added RESTful actions for update and create
Added validations to ensure that usergroup.name and user.login do not collide
Added "recipients" method to users and usergroups. This returns a list of addresses.
Usergroup#recipients will follow all nested usergroups avoiding any loops and
return only unique addresses
Fixes #73 - Add usergroup support to hosts
Fixes #244 - Remove ActiveScaffold from the usergroup pages
and finally - added owners to host edit page and other whitespaces and
mods by ohad