Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #38011 - Apply environment filter for content override #11218

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def content_override
validate_content_overrides_enabled(override_params)
end
sync_task(::Actions::Katello::Host::UpdateContentOverrides, @host, content_override_values, false)
fetch_product_content
fetch_product_content(!params.dig(:content_overrides_search, :search).nil? && Foreman::Cast.to_bool(params.dig(:content_overrides_search, :limit_to_env)))
end

api :GET, "/hosts/:host_id/subscriptions/available_release_versions", N_("Show releases available for the content host")
Expand All @@ -203,8 +203,8 @@ def enabled_repositories

private

def fetch_product_content
content_finder = ProductContentFinder.new(:consumable => @host.subscription_facet)
def fetch_product_content(limit_to_env = false)
content_finder = ProductContentFinder.new(:match_environment => limit_to_env, :consumable => @host.subscription_facet)
content = content_finder.presenter_with_overrides(@host.subscription_facet.candlepin_consumer.content_overrides)
respond_with_template_collection("index", 'repository_sets', :collection => full_result_response(content))
end
Expand Down
32 changes: 32 additions & 0 deletions test/controllers/api/v2/host_subscriptions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,38 @@ def test_find_content_overrides_with_empty_string_search
refute_equal result, "wrong"
end

def test_fetch_product_content_with_respect_to_environment
# Create fake product content and stub ProductContentFinder
pcf = mock
pcf.stubs(:presenter_with_overrides)

controller = ::Katello::Api::V2::HostSubscriptionsController.new
controller.stubs(:respond_with_template_collection)
controller.stubs(:sync_task)
controller.stubs(:validate_content_overrides_enabled)
controller.stubs(:full_result_response)
controller.instance_variable_set(:@host, @host)
controller.instance_variable_set(:@content_overrides, [{:content_label => 'some-content', :value => 1}])

# Actual tests that expect the correct parameters to be passed to 'content_override'
ProductContentFinder.expects(:new).with(match_environment: true, consumable: @host.subscription_facet).returns(pcf)
ProductContentFinder.expects(:new).with(match_environment: false, consumable: @host.subscription_facet).returns(pcf).times(3)

# Invoke the call to the controller with a variaty of parameters
# Try with limit_to_env enabled
controller.params = { :host_id => @host.id, :content_overrides_search => { :search => '', :limit_to_env => true} }
controller.send(:content_override)
# Try with limit_to_env disabled
controller.params = { :host_id => @host.id, :content_overrides_search => { :search => '', :limit_to_env => false} }
controller.send(:content_override)
# Try with limit_to_env not set - should be the same as disabled
controller.params = { :host_id => @host.id, :content_overrides_search => { :search => ''} }
controller.send(:content_override)
# Try without search params - should be the same as disabled
controller.params = { :host_id => @host.id}
controller.send(:content_override)
end

def test_find_content_overrides_with_empty_string_search_limited_to_environment
# Create Host with "fedora" and "rhel" as content
content_view = katello_content_views(:library_dev_view)
Expand Down