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 11, 2024
1 parent c08f449 commit 0732029
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 13 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
3 changes: 2 additions & 1 deletion app/controllers/katello/api/v2/host_errata_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Check failure on line 10 in app/controllers/katello/api/v2/host_errata_controller.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.
}.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
50 changes: 44 additions & 6 deletions test/models/content_view_erratum_filter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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!
Expand All @@ -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
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 0732029

Please sign in to comment.