Skip to content

Commit

Permalink
Fixes #37946 - Add 'other' option for package type in errata filters
Browse files Browse the repository at this point in the history
  • Loading branch information
qcjames53 committed Nov 5, 2024
1 parent db89c59 commit 5bd7a8a
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/katello/api/v2/host_errata_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/lib/katello/util/errata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 14 additions & 2 deletions app/models/katello/content_view_erratum_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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?
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion app/models/katello/erratum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ const CVErrataDateFilterContent = ({
{__('Bugfix')}
</p>
</SelectOption>
<SelectOption
isDisabled={!hasPermission(permissions, 'edit_content_views')}
key="other"
value="other"
>
<p style={{ marginTop: '4px' }}>
{__('Other')}
</p>
</SelectOption>
</Select>
</FlexItem>
<FlexItem span={1} spacer={{ default: 'spacerNone' }}>
Expand Down

0 comments on commit 5bd7a8a

Please sign in to comment.