Sha256: fe9d7da83885ad1bf8a7676e83f47fa3aa5b8a94bdfd213a6fe3393c3aa9e069

Contents?: true

Size: 1.71 KB

Versions: 39

Compression:

Stored size: 1.71 KB

Contents

module Katello
  module Concerns
    module Api::V2::BulkHostsExtensions
      extend ActiveSupport::Concern

      def find_bulk_hosts(permission, bulk_params, restrict_to = nil)
        #works on a structure of param_group bulk_params and transforms it into a list of systems
        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?
            @hosts = ::Host.where(id: @hosts).or(::Host.where(id: search_hosts))
          else
            @hosts = search_hosts
          end
        end

        @hosts = restrict_to.call(@hosts) if restrict_to
        @hosts = @hosts.where.not(id: 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

      def find_organization
        Organization.find_by_id(params[:organization_id])
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
katello-3.16.2 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-3.16.1.2 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-3.16.1.1 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-3.16.1 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-3.16.0 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-3.16.0.rc5.1 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-3.16.0.rc5 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-3.16.0.rc4.1 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-3.15.3.1 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-3.15.3 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-3.16.0.rc4 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-3.16.0.rc3.1 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-3.15.2 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-3.16.0.rc3 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-3.16.0.rc2.1 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-3.16.0.rc2 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-3.15.1.1 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-3.16.0.rc1.1 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-3.15.1 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-3.16.0.rc1 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb