From 93a16772e951d6b131ce06029f44921437187f1e Mon Sep 17 00:00:00 2001 From: Markus Bucher Date: Mon, 20 Sep 2021 18:04:42 +0200 Subject: [PATCH] Fixes #33525 - Add debs packages_restrict_latest --- app/controllers/katello/api/v2/debs_controller.rb | 1 + app/models/katello/deb.rb | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/katello/api/v2/debs_controller.rb b/app/controllers/katello/api/v2/debs_controller.rb index 39ef90152ce..7c236130ba1 100644 --- a/app/controllers/katello/api/v2/debs_controller.rb +++ b/app/controllers/katello/api/v2/debs_controller.rb @@ -39,6 +39,7 @@ def auto_complete_arch param :host_id, :number, :desc => N_("Host id to list applicable deb packages for") param :packages_restrict_applicable, :boolean, :desc => N_("Return deb packages that are applicable to one or more hosts (defaults to true if host_id is specified)") param :packages_restrict_upgradable, :boolean, :desc => N_("Return deb packages that are upgradable on one or more hosts") + param :packages_restrict_latest, :boolean, :desc => N_("Return only the latest version of each package") param :available_for, String, :desc => N_("Return deb packages that can be added to the specified object. Only the value 'content_view_version' is supported.") param_group :search, ::Katello::Api::V2::ApiController def index diff --git a/app/models/katello/deb.rb b/app/models/katello/deb.rb index ae3f5777c2e..b7f98ae31f2 100644 --- a/app/models/katello/deb.rb +++ b/app/models/katello/deb.rb @@ -98,7 +98,10 @@ def self.applicable_to_hosts(hosts) end def self.latest(_relation) - fail 'NotImplemented' + return relation.joins( + "LEFT JOIN (#{relation.to_sql}) AS katello_debs2 ON " \ + 'katello_debs.name=katello_debs2.name AND deb_version_cmp(katello_debs.version,katello_debs2.version) < 0' + ).where('katello_debs2.version IS NULL') end end end