Module: Katello::Api::V2::BulkExtensions

Extended by:
ActiveSupport::Concern
Included in:
HostErrataExtensions
Defined in:
app/controllers/katello/concerns/api/v2/bulk_extensions.rb

Instance Method Summary collapse

Instance Method Details

#find_bulk_items(bulk_params:, model_scope:, key: :id) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/katello/concerns/api/v2/bulk_extensions.rb', line 6

def find_bulk_items(bulk_params:, model_scope:, key: :id)
  if bulk_params.is_a?(String)
    bulk_params = ActiveSupport::JSON.decode(bulk_params).
                  deep_symbolize_keys
  end
  bulk_params[:included] ||= {}
  bulk_params[:excluded] ||= {}

  if (!bulk_params[:all]) &&
      bulk_params[:included][:ids].blank? &&
      bulk_params[:included][:search].blank?
    fail HttpErrors::BadRequest, _("No items have been specified.")
  end

  if bulk_params[:all] && !bulk_params[:included][:ids].blank?
    fail HttpErrors::BadRequest, _("Sending a list of included IDs is not allowed when all items are being selected.")
  end

  ::Katello::BulkItemsHelper.new(bulk_params: bulk_params,
                                 model_scope: model_scope,
                                 key: key).fetch
end