From 03e01fe2747b69e7a2c13be02e7f90d22e108e91 Mon Sep 17 00:00:00 2001 From: Samir Jha Date: Tue, 12 Sep 2023 19:32:07 +0000 Subject: [PATCH] Fixes #36739 - Product without any repo is added to a Sync Plan regardless the error message --- app/models/katello/product.rb | 10 +++++++++- .../details/sync-plan-add-products.controller.js | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/models/katello/product.rb b/app/models/katello/product.rb index 2acc86d7c0a..6816c537d53 100644 --- a/app/models/katello/product.rb +++ b/app/models/katello/product.rb @@ -34,6 +34,7 @@ class Product < Katello::Model validates_lengths_from_database :except => [:label] validates :provider_id, :presence => true validate :ensure_provider_type_matches_id + validate :ensure_no_sync_plans_on_empty_product validates_with Validators::KatelloNameFormatValidator, :attributes => :name validates_with Validators::KatelloLabelFormatValidator, :attributes => :label validates_with Validators::ProductUniqueAttributeValidator, :attributes => :name @@ -107,7 +108,7 @@ def repos(env, content_view = nil, include_feedless = true) end def enabled? - self.repositories.present? + self.redhat? && self.repositories.present? end delegate :cdn_configuration, :library, to: :organization @@ -263,5 +264,12 @@ def ensure_provider_type_matches_id errors.add(:base, _("Cannot associate a Red Hat provider with a custom product")) end end + + def ensure_no_sync_plans_on_empty_product + return if sync_plan_id.nil? + unless enabled? + fail _("Cannot add empty product %s to sync plan!") % name + end + end end end diff --git a/engines/bastion_katello/app/assets/javascripts/bastion_katello/sync-plans/details/sync-plan-add-products.controller.js b/engines/bastion_katello/app/assets/javascripts/bastion_katello/sync-plans/details/sync-plan-add-products.controller.js index 2740d9aa8b6..7972dc809dc 100644 --- a/engines/bastion_katello/app/assets/javascripts/bastion_katello/sync-plans/details/sync-plan-add-products.controller.js +++ b/engines/bastion_katello/app/assets/javascripts/bastion_katello/sync-plans/details/sync-plan-add-products.controller.js @@ -57,7 +57,7 @@ angular.module('Bastion.sync-plans').controller('SyncPlanAddProductsController', error = function (response) { deferred.reject(response.data.errors); - Notification.setErrorMessage(response.data.errors.base); + Notification.setErrorMessage(response.data.displayMessage); $scope.table.working = false; };