From e432bb1f32b1c1265309a9c45efd3fa80979b4b9 Mon Sep 17 00:00:00 2001 From: Quinn James Date: Wed, 23 Oct 2024 21:02:24 +0000 Subject: [PATCH] Fixes #37946 - Add 'other' option for package type in errata filters --- .../content_view_filter_rules_controller.rb | 4 +- .../api/v2/content_view_filters_controller.rb | 2 +- .../katello/api/v2/host_errata_controller.rb | 3 +- app/lib/katello/util/errata.rb | 2 + .../katello/content_view_erratum_filter.rb | 16 +++++- app/models/katello/erratum.rb | 4 +- .../content_view_erratum_filter_test.rb | 50 ++++++++++++++++--- .../Filters/CVErrataDateFilterContent.js | 9 ++++ 8 files changed, 77 insertions(+), 13 deletions(-) diff --git a/app/controllers/katello/api/v2/content_view_filter_rules_controller.rb b/app/controllers/katello/api/v2/content_view_filter_rules_controller.rb index 0b61607da58..d678f06ca5c 100644 --- a/app/controllers/katello/api/v2/content_view_filter_rules_controller.rb +++ b/app/controllers/katello/api/v2/content_view_filter_rules_controller.rb @@ -37,7 +37,7 @@ def resource_class param :errata_ids, Array, :desc => N_("erratum: IDs or a select all object") param :start_date, String, :desc => N_("erratum: start date (YYYY-MM-DD)") param :end_date, String, :desc => N_("erratum: end date (YYYY-MM-DD)") - param :types, Array, :desc => N_("erratum: types (enhancement, bugfix, security)") + param :types, Array, :desc => N_("erratum: types (enhancement, bugfix, security, other)") param :date_type, String, :desc => N_("erratum: search using the 'Issued On' or 'Updated On' column of the errata. Values are 'issued'/'updated'") param :module_stream_ids, Array, :desc => N_("module stream ids") def create @@ -88,7 +88,7 @@ def show param :errata_id, String, :desc => N_("erratum: id") param :start_date, String, :desc => N_("erratum: start date (YYYY-MM-DD)") param :end_date, String, :desc => N_("erratum: end date (YYYY-MM-DD)") - param :types, Array, :desc => N_("erratum: types (enhancement, bugfix, security)") + param :types, Array, :desc => N_("erratum: types (enhancement, bugfix, security, other)") def update update_params = rule_params update_params[:name] = update_params[:name].first if update_params[:name] diff --git a/app/controllers/katello/api/v2/content_view_filters_controller.rb b/app/controllers/katello/api/v2/content_view_filters_controller.rb index 2d9ac705783..ebbe9821701 100644 --- a/app/controllers/katello/api/v2/content_view_filters_controller.rb +++ b/app/controllers/katello/api/v2/content_view_filters_controller.rb @@ -109,7 +109,7 @@ def remove_filter_rules param :errata_ids, Array, :desc => N_("erratum: IDs or a select all object") param :start_date, String, :desc => N_("erratum: start date (YYYY-MM-DD)") param :end_date, String, :desc => N_("erratum: end date (YYYY-MM-DD)") - param :types, Array, :desc => N_("erratum: types (enhancement, bugfix, security)") + param :types, Array, :desc => N_("erratum: types (enhancement, bugfix, security, other)") param :date_type, String, :desc => N_("erratum: search using the 'Issued On' or 'Updated On' column of the errata. Values are 'issued'/'updated'") param :module_stream_ids, Array, :desc => N_("module stream ids") end diff --git a/app/controllers/katello/api/v2/host_errata_controller.rb b/app/controllers/katello/api/v2/host_errata_controller.rb index a6149f30a4f..fdaaeac20ca 100644 --- a/app/controllers/katello/api/v2/host_errata_controller.rb +++ b/app/controllers/katello/api/v2/host_errata_controller.rb @@ -7,6 +7,7 @@ class Api::V2::HostErrataController < Api::V2::ApiController bugfix: Katello::Erratum::BUGZILLA, # ['bugfix', 'recommended'] security: Katello::Erratum::SECURITY, # ['security'] enhancement: Katello::Erratum::ENHANCEMENT, # ['enhancement', 'optional'] + other: Katello::Erratum::OTHER # ['other'] }.freeze before_action :find_host, only: :index @@ -41,7 +42,7 @@ def resource_class param :content_view_id, :number, :desc => N_("Calculate Applicable Errata based on a particular Content View"), :required => false param :environment_id, :number, :desc => N_("Calculate Applicable Errata based on a particular Environment"), :required => false param :include_applicable, :bool, :desc => N_("Return errata that are applicable to this host. Defaults to false)"), :required => false - param :type, String, :desc => N_("Return only errata of a particular type (security, bugfix, enhancement)"), :required => false + param :type, String, :desc => N_("Return only errata of a particular type (security, bugfix, enhancement, other)"), :required => false param :severity, String, :desc => N_("Return only errata of a particular severity (None, Low, Moderate, Important, Critical)"), :required => false param_group :search, Api::V2::ApiController def index diff --git a/app/lib/katello/util/errata.rb b/app/lib/katello/util/errata.rb index 037644a6463..e3a85f3acfb 100644 --- a/app/lib/katello/util/errata.rb +++ b/app/lib/katello/util/errata.rb @@ -36,6 +36,8 @@ def get_pulp_filter_type(type) return ::Katello::Erratum::ENHANCEMENT when "security" return ::Katello::Erratum::SECURITY + when "other" + return ::Katello::Erratum::OTHER end end diff --git a/app/models/katello/content_view_erratum_filter.rb b/app/models/katello/content_view_erratum_filter.rb index ee8d9f98103..2c1d8d240a5 100644 --- a/app/models/katello/content_view_erratum_filter.rb +++ b/app/models/katello/content_view_erratum_filter.rb @@ -4,7 +4,8 @@ class ContentViewErratumFilter < ContentViewFilter ERRATA_TYPES = { 'bugfix' => _('Bug Fix'), 'enhancement' => _('Enhancement'), - 'security' => _('Security') }.with_indifferent_access + 'security' => _('Security'), + 'other' => _('Other') }.with_indifferent_access has_many :erratum_rules, :dependent => :destroy, :foreign_key => :content_view_filter_id, :class_name => "Katello::ContentViewErratumFilterRule" @@ -94,7 +95,14 @@ def erratum_arel def types_clause types = erratum_rules.first.types return if types.blank? - errata_types_in(types) + + conditions = [] + valid_types = Erratum::TYPES.reject { |type| type == "other" } + conditions << errata_types_in(types.reject { |type| type == "other" }) + conditions << errata_types_not_in(valid_types) if types.include?("other") + conditions.reduce(nil) do |combined_clause, condition| + combined_clause ? combined_clause.or(condition) : condition + end end def filter_by_id? @@ -105,6 +113,10 @@ def errata_types_in(types) erratum_arel[:errata_type].in(types) end + def errata_types_not_in(types) + erratum_arel[:errata_type].not_in(types) + end + def errata_in(ids) erratum_arel[:errata_id].in(ids) end diff --git a/app/models/katello/erratum.rb b/app/models/katello/erratum.rb index b68062ee1cd..70451fa2571 100644 --- a/app/models/katello/erratum.rb +++ b/app/models/katello/erratum.rb @@ -5,7 +5,8 @@ class Erratum < Katello::Model SECURITY = ["security"].freeze BUGZILLA = ["bugfix", "recommended"].freeze ENHANCEMENT = ["enhancement", "optional"].freeze - TYPES = [SECURITY, BUGZILLA, ENHANCEMENT].flatten.freeze + OTHER = ["other"].freeze + TYPES = [SECURITY, BUGZILLA, ENHANCEMENT, OTHER].flatten.freeze NONE = "None".freeze LOW = "Low".freeze @@ -55,6 +56,7 @@ def self.of_type(type) scope :security, -> { of_type(Erratum::SECURITY) } scope :bugfix, -> { of_type(Erratum::BUGZILLA) } scope :enhancement, -> { of_type(Erratum::ENHANCEMENT) } + scope :other, -> { of_type(Erratum::OTHER) } scope :modular, -> { where(:id => joins(:packages => :module_stream_errata_packages)) } scope :non_modular, -> { where.not(:id => modular) } diff --git a/test/models/content_view_erratum_filter_test.rb b/test/models/content_view_erratum_filter_test.rb index 02491f8baa9..d74b8b2dc4c 100644 --- a/test/models/content_view_erratum_filter_test.rb +++ b/test/models/content_view_erratum_filter_test.rb @@ -6,6 +6,10 @@ def setup @repo = katello_repositories(:fedora_17_x86_64) end + TYPICAL_TYPES_RESPONSE = + " AND (\"katello_errata\".\"errata_type\" IN ('bugfix', 'enhancement', 'security')"\ + " OR \"katello_errata\".\"errata_type\" NOT IN ('security', 'bugfix', 'recommended', 'enhancement', 'optional'))".freeze + def test_erratum_by_id_returns_arel_for_specified_errata_id erratum = katello_errata(:security) @repo.errata = [erratum] @@ -24,7 +28,7 @@ def test_errata_by_start_date_returns_arel_for_errata_by_updated_date_and_errata filter = id_rule.filter filter.reload - assert_equal "\"katello_errata\".\"updated\" >= '#{start_date}' AND \"katello_errata\".\"errata_type\" IN ('bugfix', 'enhancement', 'security')", + assert_equal "\"katello_errata\".\"updated\" >= '#{start_date}'" + TYPICAL_TYPES_RESPONSE, filter.generate_clauses(@repo).to_sql end @@ -35,7 +39,7 @@ def test_errata_by_start_date_returns_arel_for_errata_by_issued_date_and_errata_ filter = id_rule.filter filter.reload - assert_equal "\"katello_errata\".\"issued\" >= '#{start_date}' AND \"katello_errata\".\"errata_type\" IN ('bugfix', 'enhancement', 'security')", + assert_equal "\"katello_errata\".\"issued\" >= '#{start_date}'" + TYPICAL_TYPES_RESPONSE, filter.generate_clauses(@repo).to_sql end @@ -45,7 +49,7 @@ def test_errata_by_end_date_returns_arel_for_errata_by_updated_date_and_errata_t filter = id_rule.filter filter.reload - assert_equal "\"katello_errata\".\"updated\" <= '#{end_date}' AND \"katello_errata\".\"errata_type\" IN ('bugfix', 'enhancement', 'security')", + assert_equal "\"katello_errata\".\"updated\" <= '#{end_date}'" + TYPICAL_TYPES_RESPONSE, filter.generate_clauses(@repo).to_sql end @@ -56,7 +60,7 @@ def test_errata_by_end_date_returns_arel_for_errata_by_issued_date_and_errata_ty filter = id_rule.filter filter.reload - assert_equal "\"katello_errata\".\"issued\" <= '#{end_date}' AND \"katello_errata\".\"errata_type\" IN ('bugfix', 'enhancement', 'security')", + assert_equal "\"katello_errata\".\"issued\" <= '#{end_date}'" + TYPICAL_TYPES_RESPONSE, filter.generate_clauses(@repo).to_sql end @@ -69,6 +73,15 @@ def test_errata_by_type_returns_arel_by_errata_type filter.generate_clauses(@repo).to_sql end + def test_errata_by_type_returns_arel_by_errata_type_other + id_rule = FactoryBot.create(:katello_content_view_erratum_filter_rule, :types => ['other']) + filter = id_rule.filter + filter.reload + + assert_equal "(1=0 OR \"katello_errata\".\"errata_type\" NOT IN ('security', 'bugfix', 'recommended', 'enhancement', 'optional'))", + filter.generate_clauses(@repo).to_sql + end + def test_content_unit_pulp_ids_with_empty_errata_list_returns_empty_result rpm1 = @repo.rpms.first rpm2 = @repo.rpms.last @@ -209,13 +222,16 @@ def test_content_unit_pulp_ids_by_issued_end_date_returns_pulp_hrefs end def test_content_unit_pulp_ids_by_errata_type - rpm1 = @repo.rpms.first - rpm2 = @repo.rpms.last + rpm1 = @repo.rpms[0] + rpm2 = @repo.rpms[1] + rpm3 = @repo.rpms[2] erratum1 = Katello::Erratum.new(:pulp_id => "one", :errata_id => "ERRATA1", :errata_type => 'bugfix') erratum1.packages << Katello::ErratumPackage.new(:filename => rpm1.filename, :name => "e1", :nvrea => "e1") erratum2 = Katello::Erratum.new(:pulp_id => "two", :errata_id => "ERRATA2", :errata_type => 'security') erratum2.packages << Katello::ErratumPackage.new(:filename => rpm2.filename, :name => "e2", :nvrea => "e2") + erratum3 = Katello::Erratum.new(:pulp_id => "three", :errata_id => "ERRATA3", :errata_type => 'not_recognized') # This should be 'other' type + erratum3.packages << Katello::ErratumPackage.new(:filename => rpm3.filename, :name => "e3", :nvrea => "e3") @repo.errata = [erratum2] @repo.save! @@ -226,5 +242,27 @@ def test_content_unit_pulp_ids_by_errata_type assert_equal [rpm2.pulp_id], filter.content_unit_pulp_ids(@repo) end + + def test_content_unit_pulp_ids_by_errata_type_other + rpm1 = @repo.rpms[0] + rpm2 = @repo.rpms[1] + rpm3 = @repo.rpms[2] + + erratum1 = Katello::Erratum.new(:pulp_id => "one", :errata_id => "ERRATA1", :errata_type => 'bugfix') + erratum1.packages << Katello::ErratumPackage.new(:filename => rpm1.filename, :name => "e1", :nvrea => "e1") + erratum2 = Katello::Erratum.new(:pulp_id => "two", :errata_id => "ERRATA2", :errata_type => 'security') + erratum2.packages << Katello::ErratumPackage.new(:filename => rpm2.filename, :name => "e2", :nvrea => "e2") + erratum3 = Katello::Erratum.new(:pulp_id => "three", :errata_id => "ERRATA3", :errata_type => 'not_recognized') # This should be 'other' type + erratum3.packages << Katello::ErratumPackage.new(:filename => rpm3.filename, :name => "e3", :nvrea => "e3") + + @repo.errata = [erratum3] + @repo.save! + + id_rule = FactoryBot.create(:katello_content_view_erratum_filter_rule, :types => ['other']) + filter = id_rule.filter + filter.reload + + assert_equal [rpm3.pulp_id], filter.content_unit_pulp_ids(@repo) + end end end diff --git a/webpack/scenes/ContentViews/Details/Filters/CVErrataDateFilterContent.js b/webpack/scenes/ContentViews/Details/Filters/CVErrataDateFilterContent.js index 8eb5c2204d9..cecd49fcf7d 100644 --- a/webpack/scenes/ContentViews/Details/Filters/CVErrataDateFilterContent.js +++ b/webpack/scenes/ContentViews/Details/Filters/CVErrataDateFilterContent.js @@ -171,6 +171,15 @@ const CVErrataDateFilterContent = ({ {__('Bugfix')}

+ +

+ {__('Other')} +

+