Module: Katello::Api::V2::BulkHostsExtensions
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
Instance Method Summary collapse
- #bulk_hosts_relation(permission, org) ⇒ Object
- #find_bulk_hosts(permission, bulk_params, restrict_to = nil) ⇒ Object
- #find_organization ⇒ Object
Instance Method Details
#bulk_hosts_relation(permission, org) ⇒ Object
6 7 8 9 10 |
# File 'app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb', line 6 def bulk_hosts_relation(, org) relation = ::Host::Managed.() relation = relation.where(organization: org) if org relation end |
#find_bulk_hosts(permission, bulk_params, restrict_to = nil) ⇒ Object
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 39 40 |
# File 'app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb', line 12 def find_bulk_hosts(, bulk_params, restrict_to = nil) #works on a structure of param_group bulk_params and transforms it into a list of systems bulk_params[:included] ||= {} bulk_params[:excluded] ||= {} if !params[:install_all] && bulk_params[:included][:ids].blank? && bulk_params[:included][:search].nil? fail HttpErrors::BadRequest, _("No hosts have been specified.") end find_organization @hosts = bulk_hosts_relation(, @organization) if bulk_params[:included][:ids].present? @hosts = @hosts.where(id: bulk_params[:included][:ids]) end if bulk_params[:included][:search].present? @hosts = @hosts.search_for(bulk_params[:included][:search]) end @hosts = restrict_to.call(@hosts) if restrict_to if bulk_params[:excluded][:ids].present? @hosts = @hosts.where.not(id: bulk_params[:excluded][:ids]) end fail HttpErrors::Forbidden, _("No hosts matched search, or action unauthorized for selected hosts.") if @hosts.empty? @hosts end |
#find_organization ⇒ Object
42 43 44 |
# File 'app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb', line 42 def find_organization @organization ||= Organization.find_by_id(params[:organization_id]) end |