Skip to content

Commit

Permalink
Fixes #38117 - Refresh smart proxy sync history when proxy is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
sjha4 committed Dec 19, 2024
1 parent cf57e55 commit f764ef2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/models/katello/concerns/smart_proxy_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def refresh
before_create :associate_default_locations
before_create :associate_lifecycle_environments
before_validation :set_default_download_policy
after_update :refresh_smart_proxy_sync_histories

lazy_accessor :pulp_repositories, :initializer => lambda { |_s| pulp_node.extensions.repository.retrieve_all }

Expand Down Expand Up @@ -471,6 +472,9 @@ def add_lifecycle_environment(environment)
end

def remove_lifecycle_environment(environment)
smart_proxy_helper = ::Katello::SmartProxyHelper.new(self)
repos = smart_proxy_helper.repositories_available_to_capsule(environment)
self.clear_smart_proxy_sync_histories(repos) unless repos.empty?
self.lifecycle_environments.find(environment.id)
unless self.lifecycle_environments.destroy(environment)
fail _("Could not remove the lifecycle environment from the smart proxy")
Expand All @@ -479,6 +483,17 @@ def remove_lifecycle_environment(environment)
raise _("Lifecycle environment was not attached to the smart proxy; therefore, no changes were made.")
end

def refresh_smart_proxy_sync_histories
smart_proxy_helper = ::Katello::SmartProxyHelper.new(self)
repos = smart_proxy_helper.repositories_available_to_capsule
repo_ids = repos.map(&:id)
if repo_ids.empty?
self.smart_proxy_sync_histories.delete_all
else
self.smart_proxy_sync_histories.where("repository_id NOT IN (?)", repo_ids).delete_all
end
end

def available_lifecycle_environments(organization_id = nil)
scope = Katello::KTEnvironment.not_in_capsule(self)
scope = scope.where(organization_id: organization_id) if organization_id
Expand Down

0 comments on commit f764ef2

Please sign in to comment.