Skip to content

Commit 8950fd3

Browse files
jeremylenzclaudeqcjames53
authored
Fixes #39122 - Don't allow separate params to reset multiCV hosts (#11662)
* Fixes #39122 - Don't allow separate params to reset multiCV hosts Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * Refs #39122 - use fixtures Co-authored-by: Quinn James <35753203+qcjames53@users.noreply.github.com> --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: Quinn James <35753203+qcjames53@users.noreply.github.com>
1 parent e8e0ee6 commit 8950fd3

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

app/controllers/katello/api/v2/activation_keys_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class Api::V2::ActivationKeysController < Api::V2::ApiController # rubocop:disa
2323
param :purpose_usage, String, :desc => N_("Sets the system purpose usage")
2424
param :purpose_role, String, :desc => N_("Sets the system purpose usage")
2525

26-
param :environment, Hash, :desc => N_("Hash containing the Id of the single lifecycle environment to be associated with the activation key."), deprecated: true
27-
param :content_view_id, Integer, :desc => N_("Id of the single content view to be associated with the activation key."), :allow_nil => true
28-
param :environment_id, Integer, :desc => N_("Id of the single lifecycle environment to be associated with the activation key."), :allow_nil => true
26+
param :environment, Hash, :deprecated => true, :desc => N_("Hash containing the Id of the single lifecycle environment to be associated with the activation key.")
27+
param :content_view_id, Integer, :deprecated => true, :desc => N_("Id of the single content view to be associated with the activation key."), :allow_nil => true
28+
param :environment_id, Integer, :deprecated => true, :desc => N_("Id of the single lifecycle environment to be associated with the activation key."), :allow_nil => true
2929
param :content_view_environments, Array, :desc => N_("Comma-separated list of content view environment labels to be associated with the activation key,"\
3030
" in the format of 'lifecycle_environment_label/content_view_label'."\
3131
" Ignored if content_view_environment_ids is specified, or if content_view_id and lifecycle_environment_id are specified."\

app/controllers/katello/api/v2/host_contents_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module Katello
22
class Api::V2::HostContentsController < Katello::Api::V2::ApiController
33
def_param_group :content_facet_attributes do
4-
param :content_view_id, Integer, :desc => N_("Id of the single content view to be associated with the host.")
5-
param :lifecycle_environment_id, Integer, :desc => N_("Id of the single lifecycle environment to be associated with the host.")
4+
param :content_view_id, Integer, :deprecated => true, :desc => N_("Id of the single content view to be associated with the host. Ignored for multi-environment hosts.")
5+
param :lifecycle_environment_id, Integer, :deprecated => true, :desc => N_("Id of the single lifecycle environment to be associated with the host. Ignored for multi-environment hosts.")
66
param :content_view_environments, Array, :desc => N_("Comma-separated list of content view environment labels to be associated with the host,"\
77
" in the format of 'lifecycle_environment_label/content_view_label'."\
88
" Ignored if content_view_environment_ids is specified, or if content_view_id and lifecycle_environment_id are specified."\

app/models/katello/concerns/host_managed_extensions.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ def check_cve_attributes(attrs)
1818
# them below in add_back_cve_errors.
1919
@pending_cve_attrs = { content_view_id: cv_id, lifecycle_environment_id: lce_id }
2020
if cv_id && lce_id
21+
if content_facet&.multi_content_view_environment?
22+
Rails.logger.warn "content_view_id and lifecycle_environment_id cannot be used to reassign multi-environment host '#{name}'. Use content_view_environment_ids instead"
23+
@pending_cve_attrs = {}
24+
return
25+
end
2126
cve = content_facet&.assign_single_environment(content_view_id: cv_id, lifecycle_environment_id: lce_id)
2227
Rails.logger.warn "Couldn't assign content view environment; host has no content facet" if cve.blank?
2328
@pending_cve_attrs = {}

test/models/concerns/host_managed_extensions_test.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,29 @@ def test_yum_or_yum_transient
207207
end
208208

209209
class HostManagedExtensionsUpdateTest < HostManagedExtensionsTestBase
210+
def test_multi_environment_host_ignores_single_params
211+
::Host::Managed.any_instance.stubs(:update_candlepin_associations)
212+
host = FactoryBot.create(:host, :with_content, :with_subscription, :content_view => @library_view, :lifecycle_environment => @library)
213+
214+
# Add a second content view environment to make this a multi-environment host
215+
library_dev_view = katello_content_views(:library_dev_view)
216+
dev_env = katello_environments(:dev)
217+
second_cve = ContentViewEnvironment.find_by(content_view: library_dev_view, environment: dev_env)
218+
original_cves = host.content_facet.content_view_environments.to_a
219+
host.content_facet.content_view_environments = original_cves + [second_cve]
220+
host.save!
221+
assert host.content_facet.multi_content_view_environment?
222+
223+
# Try to update with single params
224+
host_attrs = host.attributes.deep_clone
225+
host_attrs[:content_facet_attributes] = {content_view_id: @view.id, lifecycle_environment_id: @dev.id}
226+
Rails.logger.expects(:warn).with("content_view_id and lifecycle_environment_id cannot be used to reassign multi-environment host '#{host.name}'. Use content_view_environment_ids instead")
227+
host.check_cve_attributes(host_attrs)
228+
229+
# Multi-environment host should ignore single params and keep original environments
230+
assert_equal original_cves + [second_cve], host.content_facet.content_view_environments
231+
end
232+
210233
def test_update
211234
host = FactoryBot.create(:host, :with_content, :with_subscription, :content_view => @library_view, :lifecycle_environment => @library)
212235
host.content_facet.expects(:save!)

0 commit comments

Comments
 (0)