File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed
controllers/katello/api/v2 Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,16 @@ def custom_index_relation(collection)
9898 collection
9999 end
100100
101+ def final_custom_index_relation ( collection )
102+ # :packages_restrict_latest is intended to filter the result set after all
103+ # other constraints have been applied, including the scoped_search
104+ # constraints. If any constraints are applied after this, then a package
105+ # will not be returned if its latest version does not match those
106+ # constraints, even if an older version does match those constraints.
107+ collection = Katello ::Deb . latest ( collection ) if ::Foreman ::Cast . to_bool ( params [ :packages_restrict_latest ] )
108+ collection
109+ end
110+
101111 private
102112
103113 def find_hosts
Original file line number Diff line number Diff line change @@ -96,7 +96,10 @@ def self.applicable_to_hosts(hosts)
9696 end
9797
9898 def self . latest ( _relation )
99- fail 'NotImplemented'
99+ return relation . joins (
100+ "LEFT JOIN (#{ relation . to_sql } ) AS katello_debs2 ON " \
101+ 'katello_debs.name=katello_debs2.name AND deb_version_cmp(katello_debs.version,katello_debs2.version) < 0'
102+ ) . where ( 'katello_debs2.version IS NULL' )
100103 end
101104 end
102105end
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ def models
77 @version = ContentViewVersion . first
88 @deb = katello_debs ( :one )
99 @host = hosts ( :one )
10+ @org = get_organization
1011 end
1112
1213 def setup
@@ -70,6 +71,15 @@ def test_index_with_available_for_content_view_version
7071 assert_includes ids , @deb . id
7172 end
7273
74+ def test_index_with_latest
75+ response = get :index , params : { :packages_restrict_latest => true , :organization_id => @org . id }
76+
77+ assert_response :success
78+ ids = JSON . parse ( response . body ) [ 'results' ] . map { |p | p [ 'id' ] }
79+ assert_includes ids , katello_debs ( :one_new ) . id
80+ refute_includes ids , @deb . id
81+ end
82+
7383 def test_index_protected
7484 assert_protected_action ( :index , @auth_permissions , @unauth_permissions ) do
7585 get :index , params : { :repository_id => @repo . id }
You can’t perform that action at this time.
0 commit comments