Sha256: 8c3ad23c6f03ee873ebd1b5d6475a060224b4316f6c1019d1da8750c79ee20a5

Contents?: true

Size: 1.58 KB

Versions: 75

Compression:

Stored size: 1.58 KB

Contents

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

      def bulk_hosts_relation(permission, org)
        relation = ::Host::Managed.authorized(permission)
        relation = relation.where(organization: org) if org
        relation
      end

      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
        bulk_params[:included] ||= {}
        bulk_params[:excluded] ||= {}

        if 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(permission, @organization)

        if bulk_params[:included][:ids].present?
          @hosts = @hosts.where(id: bulk_params[:included][:ids])
        end

        if bulk_params[:included][:search]
          search_hosts = bulk_hosts_relation(permission, @organization).search_for(bulk_params[:included][:search])
          @hosts = @hosts.merge(search_hosts)
        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, _("Action unauthorized to be performed on selected hosts.") if @hosts.empty?

        @hosts
      end

      def find_organization
        @organization ||= Organization.find_by_id(params[:organization_id])
      end
    end
  end
end

Version data entries

75 entries across 75 versions & 1 rubygems

Version Path
katello-4.7.6 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-4.7.5 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-4.7.4 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-4.7.3 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-4.7.2 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-4.7.1 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-4.6.2.1 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-4.6.2 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-4.7.0 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-4.6.1 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-4.7.0.rc2 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-4.7.0.rc1 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-4.4.2.2 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-4.4.2.1 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-4.4.2 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-4.5.1 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-4.6.0 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-4.6.0.rc2 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-4.6.0.rc1 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb
katello-4.5.0 app/controllers/katello/concerns/api/v2/bulk_hosts_extensions.rb