Revision 7cf99090
Added by Joseph Magen almost 10 years ago
app/models/concerns/hostext/search.rb | ||
---|---|---|
scoped_search :in => :hostgroup, :on => :title, :complete_value => true, :rename => :hostgroup_fullname
|
||
scoped_search :in => :hostgroup, :on => :title, :complete_value => true, :rename => :hostgroup_title
|
||
scoped_search :in => :hostgroup, :on => :id, :complete_value => false, :rename => :hostgroup_id, :only_explicit => true
|
||
scoped_search :in => :hostgroup, :on => :title, :complete_value => true, :rename => :parent_hostgroup, :only_explicit => true, :ext_method => :search_by_hostgroup_and_descendants
|
||
scoped_search :in => :domain, :on => :name, :complete_value => true, :rename => :domain
|
||
scoped_search :in => :domain, :on => :id, :complete_value => true, :rename => :domain_id
|
||
scoped_search :in => :realm, :on => :name, :complete_value => true, :rename => :realm
|
||
... | ... | |
return {:conditions => opts, :include => :hostgroup}
|
||
end
|
||
|
||
def search_by_hostgroup_and_descendants(key, operator, value)
|
||
conditions = sanitize_sql_for_conditions(["hostgroups.title #{operator} ?", value_to_sql(operator, value)])
|
||
# Only one hostgroup (first) is used to determined descendants. Future TODO - alert if result results more than one hostgroup
|
||
hostgroup = Hostgroup.unscoped.with_taxonomy_scope.where(conditions).first
|
||
hostgroup_ids = hostgroup.subtree_ids
|
||
if hostgroup_ids.any?
|
||
opts = "hosts.hostgroup_id IN (#{hostgroup_ids.join(',')})"
|
||
else
|
||
opts = "hosts.id < 0"
|
||
end
|
||
return {:conditions => opts}
|
||
end
|
||
|
||
def search_by_params(key, operator, value)
|
||
key_name = key.sub(/^.*\./,'')
|
||
condition = sanitize_sql_for_conditions(["name = ? and value #{operator} ?", key_name, value_to_sql(operator, value)])
|
Also available in: Unified diff
fixes #6116 - search hosts by parent host group and its decendants