From 7b9ce64929d537e340b8dea7ec461fc4df019ea8 Mon Sep 17 00:00:00 2001 From: Nadja Heitmann Date: Mon, 11 Nov 2024 13:44:37 +0000 Subject: [PATCH 01/29] Fixes #38011 - Apply environment filter for content override --- .../api/v2/host_subscriptions_controller.rb | 6 ++-- .../v2/host_subscriptions_controller_test.rb | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/app/controllers/katello/api/v2/host_subscriptions_controller.rb b/app/controllers/katello/api/v2/host_subscriptions_controller.rb index 865dac810e1..04400d68afa 100644 --- a/app/controllers/katello/api/v2/host_subscriptions_controller.rb +++ b/app/controllers/katello/api/v2/host_subscriptions_controller.rb @@ -184,7 +184,7 @@ def content_override validate_content_overrides_enabled(override_params) end sync_task(::Actions::Katello::Host::UpdateContentOverrides, @host, content_override_values, false) - fetch_product_content + fetch_product_content(!params.dig(:content_overrides_search, :search).nil? && Foreman::Cast.to_bool(params.dig(:content_overrides_search, :limit_to_env))) end api :GET, "/hosts/:host_id/subscriptions/available_release_versions", N_("Show releases available for the content host") @@ -203,8 +203,8 @@ def enabled_repositories private - def fetch_product_content - content_finder = ProductContentFinder.new(:consumable => @host.subscription_facet) + def fetch_product_content(limit_to_env = false) + content_finder = ProductContentFinder.new(:match_environment => limit_to_env, :consumable => @host.subscription_facet) content = content_finder.presenter_with_overrides(@host.subscription_facet.candlepin_consumer.content_overrides) respond_with_template_collection("index", 'repository_sets', :collection => full_result_response(content)) end diff --git a/test/controllers/api/v2/host_subscriptions_controller_test.rb b/test/controllers/api/v2/host_subscriptions_controller_test.rb index eaad900c11e..7af50624e94 100644 --- a/test/controllers/api/v2/host_subscriptions_controller_test.rb +++ b/test/controllers/api/v2/host_subscriptions_controller_test.rb @@ -239,6 +239,38 @@ def test_find_content_overrides_with_empty_string_search refute_equal result, "wrong" end + def test_fetch_product_content_with_respect_to_environment + # Create fake product content and stub ProductContentFinder + pcf = mock + pcf.stubs(:presenter_with_overrides) + + controller = ::Katello::Api::V2::HostSubscriptionsController.new + controller.stubs(:respond_with_template_collection) + controller.stubs(:sync_task) + controller.stubs(:validate_content_overrides_enabled) + controller.stubs(:full_result_response) + controller.instance_variable_set(:@host, @host) + controller.instance_variable_set(:@content_overrides, [{:content_label => 'some-content', :value => 1}]) + + # Actual tests that expect the correct parameters to be passed to 'content_override' + ProductContentFinder.expects(:new).with(match_environment: true, consumable: @host.subscription_facet).returns(pcf) + ProductContentFinder.expects(:new).with(match_environment: false, consumable: @host.subscription_facet).returns(pcf).times(3) + + # Invoke the call to the controller with a variaty of parameters + # Try with limit_to_env enabled + controller.params = { :host_id => @host.id, :content_overrides_search => { :search => '', :limit_to_env => true} } + controller.send(:content_override) + # Try with limit_to_env disabled + controller.params = { :host_id => @host.id, :content_overrides_search => { :search => '', :limit_to_env => false} } + controller.send(:content_override) + # Try with limit_to_env not set - should be the same as disabled + controller.params = { :host_id => @host.id, :content_overrides_search => { :search => ''} } + controller.send(:content_override) + # Try without search params - should be the same as disabled + controller.params = { :host_id => @host.id} + controller.send(:content_override) + end + def test_find_content_overrides_with_empty_string_search_limited_to_environment # Create Host with "fedora" and "rhel" as content content_view = katello_content_views(:library_dev_view) From f07701af308530a2c1c5f70d6a01711998ab3ead Mon Sep 17 00:00:00 2001 From: Nadja Heitmann Date: Thu, 12 Dec 2024 17:02:57 +0100 Subject: [PATCH 02/29] Fixes #38083 - Add repository filter to Debian packages page (#11255) --- .../bastion_katello/debs/debs.controller.js | 68 +++++++++++++------ .../bastion_katello/debs/views/debs.html | 4 ++ .../test/debs/debs.controller.test.js | 25 ++++++- 3 files changed, 73 insertions(+), 24 deletions(-) diff --git a/engines/bastion_katello/app/assets/javascripts/bastion_katello/debs/debs.controller.js b/engines/bastion_katello/app/assets/javascripts/bastion_katello/debs/debs.controller.js index 4cf9adb0c7d..7a2e6ca390e 100644 --- a/engines/bastion_katello/app/assets/javascripts/bastion_katello/debs/debs.controller.js +++ b/engines/bastion_katello/app/assets/javascripts/bastion_katello/debs/debs.controller.js @@ -1,38 +1,52 @@ -(function () { - 'use strict'; - - /** - * @ngdoc controller - * @name Bastion.debs.controller:DebsController - * - * @description - * Handles fetching deb packages and populating Nutupane based on the current - * ui-router state. - * - * @requires translate - * - */ - function DebsController($scope, $location, translate, Nutupane, Deb, CurrentOrganization) { +/** + * @ngdoc controller + * @name Bastion.debs.controller:DebsController + * + * @description + * Handles fetching deb packages and populating Nutupane based on the current + * ui-router state. + * + * @requires translate + * + */ +angular.module('Bastion.debs').controller('DebsController', + ['$scope', '$location', 'translate', 'Nutupane', 'Deb', 'Repository', 'CurrentOrganization', + function DebsController($scope, $location, translate, Nutupane, Deb, Repository, CurrentOrganization) { var nutupane; var params = { 'organization_id': CurrentOrganization, 'search': $location.search().search || "", + 'repository_id': $location.search().repositoryId || null, 'paged': true, 'sort_by': 'name', 'sort_order': 'ASC' }; - nutupane = new Nutupane(Deb, params); + nutupane = $scope.nutupane = new Nutupane(Deb, params); nutupane.primaryOnly = true; $scope.table = nutupane.table; // Labels so breadcrumb strings can be translated $scope.label = translate('Debs'); + $scope.repositoriesLabel = translate('Repositories'); $scope.controllerName = 'katello_debs'; + $scope.repository = {name: translate('All Repositories'), id: 'all'}; + + Repository.queryUnpaged({'organization_id': CurrentOrganization, 'content_type': 'deb', 'with_content': 'deb'}, function (response) { + $scope.repositories = [$scope.repository]; + $scope.repositories = $scope.repositories.concat(response.results); + + if ($location.search().repositoryId) { + $scope.repository = _.find($scope.repositories, function (repository) { + return repository.id === parseInt($location.search().repositoryId, 10); + }); + } + }); + Deb.queryPaged({'organization_id': CurrentOrganization}, function (result) { $scope.packageCount = result.total; }); @@ -50,12 +64,22 @@ nutupane.refresh(); }; - } + $scope.$watch('repository', function (repository) { + var nutupaneParams = nutupane.getParams(); - angular - .module('Bastion.debs') - .controller('DebsController', DebsController); + if (repository.id === 'all') { + nutupaneParams['repository_id'] = null; + nutupane.setParams(nutupaneParams); + } else { + $location.search('repositoryId', repository.id); + nutupaneParams['repository_id'] = repository.id; + nutupane.setParams(nutupaneParams); + } - DebsController.$inject = ['$scope', '$location', 'translate', 'Nutupane', 'Deb', 'CurrentOrganization']; + if (!nutupane.table.initialLoad) { + nutupane.refresh(); + } + }); -})(); + }] +); diff --git a/engines/bastion_katello/app/assets/javascripts/bastion_katello/debs/views/debs.html b/engines/bastion_katello/app/assets/javascripts/bastion_katello/debs/views/debs.html index 935a718c314..01c2219bdc4 100644 --- a/engines/bastion_katello/app/assets/javascripts/bastion_katello/debs/views/debs.html +++ b/engines/bastion_katello/app/assets/javascripts/bastion_katello/debs/views/debs.html @@ -6,6 +6,10 @@

Deb Packages

+
+ +
+