Skip to content

Commit

Permalink
Refs #37772 - address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz committed Sep 26, 2024
1 parent 8f3df28 commit 4950a76
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def find_content_view_environments
find_cve_for_single
elsif params[:content_view_environments] || params[:content_view_environment_ids]
@content_view_environments = ::Katello::ContentViewEnvironment.fetch_content_view_environments(
candlepin_names: params[:content_view_environments],
labels: params[:content_view_environments],
ids: params[:content_view_environment_ids],
organization: @organization || @activation_key&.organization)
if @content_view_environments.blank?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def set_content_view_environments
return if content_facet_attributes.blank? || @host&.content_facet.blank? ||
(cve_params[:content_view_id].present? && cve_params[:lifecycle_environment_id].present?)
cves = ::Katello::ContentViewEnvironment.fetch_content_view_environments(
candlepin_names: cve_params[:content_view_environments],
labels: cve_params[:content_view_environments],
ids: cve_params[:content_view_environment_ids],
organization: @organization || @host&.organization)
if cves.present?
Expand Down
6 changes: 3 additions & 3 deletions app/models/katello/content_view_environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ def priority(content_object)
end
end

def self.fetch_content_view_environments(candlepin_names: [], ids: [], organization:)
def self.fetch_content_view_environments(labels: [], ids: [], organization:)
# Must do maps here to ensure CVEs remain in the same order.
# Using ActiveRecord .where will return them in a different order.
if ids.present?
cves = ids.map do |id|
::Katello::ContentViewEnvironment.find_by(id: id)
end
cves.compact
elsif candlepin_names.present?
environment_names = candlepin_names.map(&:strip)
elsif labels.present?
environment_names = labels.map(&:strip)
environment_names.map! do |name|
with_candlepin_name(name, organization: organization)
end
Expand Down
2 changes: 1 addition & 1 deletion test/models/content_view_environment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_fetch_content_view_environments_candlepin_names
dev = katello_environments(:dev)
view = katello_content_views(:library_dev_view)
cve = Katello::ContentViewEnvironment.where(:environment_id => dev, :content_view_id => view).first
assert_equal [cve], ContentViewEnvironment.fetch_content_view_environments(candlepin_names: ['published_dev_view_dev'], organization: dev.organization)
assert_equal [cve], ContentViewEnvironment.fetch_content_view_environments(labels: ['published_dev_view_dev'], organization: dev.organization)
end

def test_fetch_content_view_environments_ids
Expand Down

0 comments on commit 4950a76

Please sign in to comment.