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)
98
98
collection
99
99
end
100
100
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
+
101
111
private
102
112
103
113
def find_hosts
Original file line number Diff line number Diff line change @@ -96,7 +96,10 @@ def self.applicable_to_hosts(hosts)
96
96
end
97
97
98
98
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' )
100
103
end
101
104
end
102
105
end
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ def models
7
7
@version = ContentViewVersion . first
8
8
@deb = katello_debs ( :one )
9
9
@host = hosts ( :one )
10
+ @org = get_organization
10
11
end
11
12
12
13
def setup
@@ -70,6 +71,15 @@ def test_index_with_available_for_content_view_version
70
71
assert_includes ids , @deb . id
71
72
end
72
73
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
+
73
83
def test_index_protected
74
84
assert_protected_action ( :index , @auth_permissions , @unauth_permissions ) do
75
85
get :index , params : { :repository_id => @repo . id }
You can’t perform that action at this time.
0 commit comments