From 5bd7a8a6e37bb7b7f40353d5837d1540fd11f5c3 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
---
.../v2/content_view_filter_rules_controller.rb | 4 ++--
.../api/v2/content_view_filters_controller.rb | 2 +-
.../katello/api/v2/host_errata_controller.rb | 5 +++--
app/lib/katello/util/errata.rb | 2 ++
.../katello/content_view_erratum_filter.rb | 16 ++++++++++++++--
app/models/katello/erratum.rb | 4 +++-
.../Details/Filters/CVErrataDateFilterContent.js | 9 +++++++++
7 files changed, 34 insertions(+), 8 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 efe1ce5c25e..fdaaeac20ca 100644
--- a/app/controllers/katello/api/v2/host_errata_controller.rb
+++ b/app/controllers/katello/api/v2/host_errata_controller.rb
@@ -6,7 +6,8 @@ class Api::V2::HostErrataController < Api::V2::ApiController
TYPES_FROM_PARAMS = {
bugfix: Katello::Erratum::BUGZILLA, # ['bugfix', 'recommended']
security: Katello::Erratum::SECURITY, # ['security']
- enhancement: Katello::Erratum::ENHANCEMENT # ['enhancement', 'optional']
+ 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/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')}
+
+