Class: Katello::Api::V2::ProductsBulkActionsController

Inherits:
ApiController
  • Object
show all
Defined in:
app/controllers/katello/api/v2/products_bulk_actions_controller.rb

Instance Method Summary collapse

Methods inherited from ApiController

#full_result_response, #resource_class, #scoped_search

Methods included from Rendering

#respond_for_async, #respond_for_bulk_async, #respond_for_create, #respond_for_destroy, #respond_for_index, #respond_for_show, #respond_for_status, #respond_for_update, #respond_with_template, #respond_with_template_collection, #respond_with_template_resource, #try_specific_collection_template, #try_specific_resource_template

Methods included from Katello::Api::Version2

#api_version

Instance Method Details

#destroy_productsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/katello/api/v2/products_bulk_actions_controller.rb', line 7

def destroy_products
  deletable_products = @products.deletable #.select{|p| p.user_deletable?}
  deletable_products.each do |prod|
    async_task(::Actions::Katello::Product::Destroy, prod)
  end

  messages = format_bulk_action_messages(
    :success    => _("Successfully initiated removal of %s product(s)"),
    :error      => _("You were not allowed to delete %s"),
    :models     => @products,
    :authorized => deletable_products
  )

  respond_for_show :template => 'bulk_action', :resource_name => 'common',
                   :resource => { 'displayMessages' => messages }
end

#sync_productsObject



26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/katello/api/v2/products_bulk_actions_controller.rb', line 26

def sync_products
  syncable_products = @products.syncable
  syncable_repositories = Repository.where(:product_id => syncable_products).has_url

  task = async_task(::Actions::BulkAction,
                    ::Actions::Katello::Repository::Sync,
                    syncable_repositories)

  respond_for_async :resource => task
end

#update_sync_plansObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/katello/api/v2/products_bulk_actions_controller.rb', line 40

def update_sync_plans
  editable_products = @products.editable
  editable_products.each do |product|
    product.sync_plan_id = params[:plan_id]
    product.save!
  end

  messages = format_bulk_action_messages(
    :success    => _("Successfully changed sync plan for %s product(s)"),
    :error      => _("You were not allowed to change sync plan for %s"),
    :models     => @products,
    :authorized => editable_products
  )

  respond_for_show :template => 'bulk_action', :resource_name => 'common',
                   :resource => { 'displayMessages' => messages }
end