diff --git a/app/controllers/katello/api/v2/repositories_bulk_actions_controller.rb b/app/controllers/katello/api/v2/repositories_bulk_actions_controller.rb index 7645aa96335..daad40af8ef 100644 --- a/app/controllers/katello/api/v2/repositories_bulk_actions_controller.rb +++ b/app/controllers/katello/api/v2/repositories_bulk_actions_controller.rb @@ -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"), @@ -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 diff --git a/app/lib/actions/katello/product/destroy.rb b/app/lib/actions/katello/product/destroy.rb index b0d27f5a6b7..a4660c9c4b9 100644 --- a/app/lib/actions/katello/product/destroy.rb +++ b/app/lib/actions/katello/product/destroy.rb @@ -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 diff --git a/app/views/katello/api/v2/products/show.json.rabl b/app/views/katello/api/v2/products/show.json.rabl index 3839c6c9c73..34ea5b8434f 100644 --- a/app/views/katello/api/v2/products/show.json.rabl +++ b/app/views/katello/api/v2/products/show.json.rabl @@ -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