76
77
78
79
80
81
82
83
84
85
|
# File 'app/models/concerns/foreman_ansible/host_managed_extensions.rb', line 76
def search_by_role(_key, operator, value)
conditions = sanitize_sql_for_conditions(["ansible_roles.name #{operator} ?", value_to_sql(operator, value)])
host_ids = ::Host::Managed.joins(:ansible_roles).where(conditions).distinct.pluck(:id)
hostgroup_ids = ::Hostgroup.unscoped.with_taxonomy_scope.joins(:ansible_roles).where(conditions).map(&:subtree_ids).flatten
conds = []
conds << "hosts.id IN(#{host_ids.join(',')})" if host_ids.present?
conds << "hosts.hostgroup_id IN(#{hostgroup_ids.uniq.join(',')})" if hostgroup_ids.present?
{ conditions: conds.join(' OR ').presence || '1 = 0' }
end
|