Skip to content

Commit

Permalink
Fixes #33525 - Add debs packages_restrict_latest
Browse files Browse the repository at this point in the history
  • Loading branch information
m-bucher committed Dec 22, 2023
1 parent df80f7b commit 91d6332
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/models/katello/deb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,13 @@ def self.applicable_to_hosts(hosts)
where("#{Katello::Host::ContentFacet.table_name}.host_id" => hosts).distinct
end

def self.latest(_relation)
fail 'NotImplemented'
def self.latest(relation)
# This might be very slow
return relation.joins(
"LEFT OUTER JOIN(#{relation.to_sql}) AS katello_debs2 ON " \
'katello_debs.name = katello_debs2.name AND katello_debs.architecture = katello_debs2.architecture AND ' \
'deb_version_cmp(katello_debs.version, katello_debs2.version) < 0 ' \
).where('katello_debs2.id IS NULL')
end
end
end
10 changes: 10 additions & 0 deletions test/controllers/api/v2/debs_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def models
@version = ContentViewVersion.first
@deb = katello_debs(:one)
@host = hosts(:one)
@org = get_organization
end

def setup
Expand Down Expand Up @@ -70,6 +71,15 @@ def test_index_with_available_for_content_view_version
assert_includes ids, @deb.id
end

def test_index_with_latest
response = get :index, params: { :packages_restrict_latest => true, :organization_id => @org.id }

assert_response :success
ids = JSON.parse(response.body)['results'].map { |p| p['id'] }
assert_includes ids, katello_debs(:one_new).id
refute_includes ids, @deb.id
end

def test_index_protected
assert_protected_action(:index, @auth_permissions, @unauth_permissions) do
get :index, params: { :repository_id => @repo.id }
Expand Down

0 comments on commit 91d6332

Please sign in to comment.