Skip to content

Commit

Permalink
Missed CVE check
Browse files Browse the repository at this point in the history
  • Loading branch information
parthaa committed Sep 11, 2024
1 parent 2dbc627 commit c877d96
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,7 @@ def available_incremental_updates
version_environment[:environments] << cve.environment unless version_environment[:environments].include?(cve.environment)
version_environment[:next_version] ||= version.next_incremental_version
version_environment[:content_host_count] ||= 0
version_environment[:content_host_count] += content_facets.in_content_views_and_environments(
content_views: [cve.content_view],
lifecycle_environments: [cve.environment]
).count
version_environment[:content_host_count] += content_facets.with_content_view_environments(cve).count

if version.content_view.composite?
version_environment[:components] = version.components_needing_errata(@errata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,7 @@ def authorize_remove_environments(view, options) # rubocop:disable Metrics/Cyclo
# and also ensure that the environments have the remove permission
return deny_access unless KTEnvironment.promotable.where(:id => env_ids).count == env_ids.size && view.promotable_or_removable?

total_count = Katello::Host::ContentFacet.in_content_views_and_environments(
:content_views => [view],
:lifecycle_environments => ::Katello::KTEnvironment.where(id: env_ids)
).count
total_count = Katello::Host::ContentFacet.with_content_views(view).with_environments(env_ids).count
if total_count > 0
unless options[:system_content_view_id] && options[:system_environment_id]
fail _("Unable to reassign content hosts. Please provide system_content_view_id and system_environment_id.")
Expand Down
5 changes: 1 addition & 4 deletions app/mailers/katello/errata_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ def promote_errata(options)
::User.as(user.login) do
@content_view = options[:content_view]
@environment = options[:environment]
@content_facets = Katello::Host::ContentFacet.in_content_views_and_environments(
:lifecycle_environments => [@environment],
:content_views => [@content_view]
)
@content_facets = Katello::Host::ContentFacet.with_content_views(@content_view).with_environments(@environment)
@hosts = ::Host::Managed.authorized("view_hosts").where(:id => @content_facets.pluck(:host_id))
@errata = @content_facets.map(&:installable_errata).flatten.uniq

Expand Down
10 changes: 2 additions & 8 deletions app/models/katello/content_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,7 @@ def update_host_statuses(environment)
# update errata applicability counts for all hosts in the CV & LE
Location.no_taxonomy_scope do
User.as_anonymous_admin do
::Katello::Host::ContentFacet.in_content_views_and_environments(
content_views: [self],
lifecycle_environments: [environment]
).each do |facet|
::Katello::Host::ContentFacet.with_content_views(self).with_environments(environment).each do |facet|
facet.update_applicability_counts
facet.update_errata_status
rescue NoMethodError
Expand Down Expand Up @@ -702,10 +699,7 @@ def check_composite_action_allowed!(env)
def check_orphaned_content_facets!(environments: [])
Location.no_taxonomy_scope do
User.as_anonymous_admin do
::Katello::Host::ContentFacet.in_content_views_and_environments(
content_views: [self],
lifecycle_environments: environments
).each do |facet|
::Katello::Host::ContentFacet.with_content_views(self).with_environments(environments).each do |facet|
unless facet.host
fail _("Orphaned content facets for deleted hosts exist for the content view and environment. Please run rake task : katello:clean_orphaned_facets and try again!")
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/katello/content_view_environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def hosts
end

def activation_keys
::Katello::ActivationKey.in_content_views_and_environments(:content_views => self.content_view, :lifecycle_environments => self.environment)
::Katello::ActivationKey.with_content_views(self.content_view).with_environments(self.environment)
end

def default_environment?
Expand Down
15 changes: 15 additions & 0 deletions app/models/katello/host/content_facet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ class ContentFacet < Katello::Model
validates_associated :content_view_environment_content_facets, :message => _("invalid: The content source must sync the lifecycle environment assigned to the host. See the logs for more information.")
validates :host, :presence => true, :allow_blank => false

scope :with_environments, ->(lifecycle_environments) do
joins(:content_view_environment_content_facets => :content_view_environment).
where("#{::Katello::ContentViewEnvironment.table_name}.environment_id" => lifecycle_environments)
end

scope :with_content_views, ->(content_views) do
joins(:content_view_environment_content_facets => :content_view_environment).
where("#{::Katello::ContentViewEnvironment.table_name}.content_view_id" => content_views)
end

scope :with_content_view_environments, ->(content_view_environments) do
joins(:content_view_environment_content_facets => :content_view_environment).
where("#{::Katello::ContentViewEnvironment.table_name}.id" => content_view_environments)
end

attr_accessor :cves_changed

def initialize(*args)
Expand Down

0 comments on commit c877d96

Please sign in to comment.