Class: Katello::Api::V2::RepositoriesBulkActionsController

Inherits:
ApiController
  • Object
show all
Defined in:
app/controllers/katello/api/v2/repositories_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_repositoriesObject



7
8
9
10
11
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
41
42
# File 'app/controllers/katello/api/v2/repositories_bulk_actions_controller.rb', line 7

def destroy_repositories
  deletion_authorized_repositories = @repositories.deletable
  unpromoted_repos = deletion_authorized_repositories.reject { |repo| repo.promoted? }
  deletable_repositories = unpromoted_repos.reject { |repo| repo.redhat? }

  messages1 = format_bulk_action_messages(
      :success    => "",
      :error      => _("You do not have permissions to delete %s"),
      :models     => @repositories,
      :authorized => deletion_authorized_repositories
  )

  messages2 = format_bulk_action_messages(
      :success    => "",
      :error      => _("Repository %s cannot be deleted since it has already been included in a published Content View."),
      :models     => deletion_authorized_repositories,
      :authorized => unpromoted_repos
  )

  messages3 = format_bulk_action_messages(
      :success    => "",
      :error      => _("Repository %s cannot be deleted since they are Red Hat repositories."),
      :models     => unpromoted_repos,
      :authorized => deletable_repositories
  )

  errors = messages3[:error] + messages1[:error] + messages2[:error]

  task = nil
  if deletable_repositories.count > 0
    task = async_task(::Actions::BulkAction, ::Actions::Katello::Repository::Destroy, deletable_repositories)
  else
    status = 400
  end
  respond_for_bulk_async :resource => OpenStruct.new(:task => task, :errors => errors), :status => status
end

#sync_repositoriesObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/katello/api/v2/repositories_bulk_actions_controller.rb', line 46

def sync_repositories
  syncable_repositories = @repositories.syncable.has_url
  if syncable_repositories.empty?
    msg = _("Unable to synchronize any repository. You either do not have the permission to"\
            " synchronize or the selected repositories do not have a feed url.")
    fail HttpErrors::UnprocessableEntity, msg
  else
    task = async_task(::Actions::BulkAction,
                      ::Actions::Katello::Repository::Sync,
                      syncable_repositories)

    respond_for_async :resource => task
  end
end