6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb', line 6
def find_bulk_hosts(permission, bulk_params, restrict_to = nil)
organization = find_organization
bulk_params[:included] ||= {}
bulk_params[:excluded] ||= {}
@hosts = []
unless bulk_params[:included][:ids].blank?
@hosts = ::Host::Managed.authorized(permission).where(:id => bulk_params[:included][:ids])
@hosts = @hosts.where(:organization_id => organization.id) if organization
end
if bulk_params[:included][:search]
search_hosts = ::Host::Managed.authorized(permission)
search_hosts = search_hosts.where(:organization_id => organization_id) if params[:organization_id]
search_hosts = search_hosts.search_for(bulk_params[:included][:search])
if @hosts.any?
::Host.where("id in (?) OR id in (?)", @hosts, search_hosts)
else
@hosts = search_hosts
end
end
@hosts = restrict_to.call(@hosts) if restrict_to
@hosts = @hosts.where('id not in (?)', bulk_params[:excluded][:ids]) unless bulk_params[:excluded][:ids].blank?
if bulk_params[:included][:ids].blank? && bulk_params[:included][:search].nil?
fail HttpErrors::BadRequest, _("No hosts have been specified.")
elsif @hosts.empty?
fail HttpErrors::Forbidden, _("Action unauthorized to be performed on selected hosts.")
end
@hosts
end
|