Skip to content

Commit

Permalink
Fixes #36577 - Handle bulk repo and product deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
sjha4 committed Jul 13, 2023
1 parent 5c99a80 commit f31c229
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Api::V2::RepositoriesBulkActionsController < Api::V2::ApiController
def destroy_repositories
deletion_authorized_repositories = @repositories.deletable
unpromoted_repos = deletion_authorized_repositories.reject { |repo| repo.promoted? && repo.content_views.generated_for_none.exists? }

unpromoted_repos_non_last_affected_repo = unpromoted_repos.reject {|repo| repo.filters.any? {|filter| filter.repositories.size == 1}}
messages1 = format_bulk_action_messages(
:success => "",
:error => _("You do not have permissions to delete %s"),
Expand All @@ -17,16 +17,23 @@ def destroy_repositories

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

errors = messages1[:error] + messages2[:error]
messages3 = format_bulk_action_messages(
:success => "",
:error => _("Repository %s cannot be deleted since it is the last affected repository in a filter. Use repository details page to delete."),
:models => unpromoted_repos,
:authorized => unpromoted_repos_non_last_affected_repo
)

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

task = nil
if unpromoted_repos.any?
task = async_task(::Actions::BulkAction, ::Actions::Katello::Repository::Destroy, unpromoted_repos)
if unpromoted_repos_non_last_affected_repo.any?
task = async_task(::Actions::BulkAction, ::Actions::Katello::Repository::Destroy, unpromoted_repos_non_last_affected_repo)
else
status = 400
end
Expand Down
3 changes: 3 additions & 0 deletions app/lib/actions/katello/product/destroy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def plan(product, options = {})
elsif !product.published_content_view_versions.not_ignorable.empty?
fail _("Cannot delete product with repositories published in a content view. Product: %{product}, %{view_versions}") %
{ :product => product.name, :view_versions => view_versions(product) }
elsif product.repositories.any?{|repo| repo.filters.any? {|filter| filter.repositories.size == 1}}
fail _("Cannot delete product: %{product} with repositories that are the last affected repository in content view filters. Delete these repositories before deleting product.") %
{ :product => product.name }
end
end

Expand Down
3 changes: 3 additions & 0 deletions app/views/katello/api/v2/products/show.json.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ node(:published_content_view_ids) do |product|
product.published_content_views.map(&:id).uniq
end

node(:has_last_affected_repo_in_filter) do |product|
product.repositories.any? {|repo| repo.filters.any? {|filter| filter.repositories.size == 1}}
end
node :redhat do |product|
product.redhat?
end
Expand Down

0 comments on commit f31c229

Please sign in to comment.