Skip to content

Commit a46d7af

Browse files
jeremylenzclaude
andauthored
Fixes #39330 - Remove deprecated CV/LCE params from hosts, AKs, hostgroups (#11753)
* Fixes #39330 - Remove deprecated CV/LCE params from hosts, AKs, hostgroups Remove the deprecated separate content_view_id and lifecycle_environment_id API parameters that were replaced by content_view_environment_ids (hosts/AKs) and content_view_environment_id (hostgroups) in 6.19. Since 7.0 allows breaking changes, this fully removes the backward-compatibility layer. Key changes: - Remove assign_single_environment from ContentFacet and ActivationKey (fixes incorrect first_or_create behavior in AK version) - Add ContentViewEnvironment.find_by_cv_and_lce! class method - Remove check_cve_attributes and related backward-compat in HostManagedExtensions - Simplify Hostgroup::ContentFacet by removing pending variable machinery - Remove setter delegates from HostgroupExtensions - Update ERB host form to use single CVEnv dropdown - Update JS to use content_view_environment_id instead of separate cascading dropdowns - Update parameter filters in plugin.rb - Remove deprecated params from API controllers and RABL responses Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Fixes #39330 - Update tests for deprecated CV/LCE param removal Update content_facet_ignore_update? to check content_view_environment_ids instead of the removed content_view_id/lifecycle_environment_id params. Without this, Host.new with content_facet_attributes would silently reject the nested attributes and not build the content facet. Update all test files to use content_view_environment_ids (hosts) and content_view_environment_id (hostgroups) instead of the removed params. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e52bb97 commit a46d7af

77 files changed

Lines changed: 910 additions & 1614 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/assets/javascripts/katello/hosts/host_and_hostgroup_edit.js

Lines changed: 38 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,24 @@ KT.hosts = {};
44
$(document).on('ContentLoad', function(){
55
KT.hosts.onKatelloHostEditLoad();
66
window.tfm.hosts.registerPluginAttributes("os",
7-
['lifecycle_environment_id', 'content_view_id', 'environment_id', 'content_source_id', 'architecture_id', 'parent_id']);
8-
9-
$("#hostgroup_lifecycle_environment_id").on("change",KT.hosts.environmentChanged);
10-
$("#host_lifecycle_environment_id").on("change", KT.hosts.environmentChanged);
7+
['content_view_environment_id', 'content_source_id', 'architecture_id', 'parent_id']);
118

129
KT.hosts.update_media_enablement();
1310
KT.hosts.set_media_selection_bindings();
1411
});
1512

1613
KT.hosts.contentSourceChanged = function() {
17-
$("#hostgroup_lifecycle_environment_id").val("");
18-
$("#host_lifecycle_environment_id").val("");
1914
$("#hostgroup_content_view_environment_id").val("");
20-
KT.hosts.fetchEnvironments();
21-
KT.hosts.environmentChanged();
15+
$("#host_content_view_environment_id").val("");
2216
KT.hosts.refreshContentViewEnvironments();
2317
};
2418

25-
KT.hosts.environmentChanged = function() {
26-
// if we don't save the currently selected view it's likely
27-
// it will be undefined in toggle_installation_medium due to the CV dropdown reload
28-
var previous_content_view = KT.hosts.getSelectedContentView();
29-
30-
KT.hosts.fetchContentViews();
31-
KT.hosts.toggle_installation_medium(previous_content_view);
32-
};
33-
3419
KT.hosts.refreshContentViewEnvironments = function() {
3520
var select = $("#hostgroup_content_view_environment_id");
36-
if (select.length === 0) return; // Only for hostgroups
21+
if (select.length === 0) {
22+
select = $("#host_content_view_environment_id");
23+
}
24+
if (select.length === 0) return;
3725

3826
var content_source_id = $('#content_source_id').val();
3927
var orgIdsElem = $("#hostgroup_organization_ids");
@@ -43,7 +31,10 @@ KT.hosts.refreshContentViewEnvironments = function() {
4331
orgIds = orgIdsElem.data('useds');
4432
}
4533
if (orgIds === undefined || orgIds === null || orgIds.length === 0) {
46-
return; // Can't fetch without organization
34+
orgIds = [$("#host_organization_id").val()];
35+
}
36+
if (orgIds === undefined || orgIds === null || orgIds.length === 0) {
37+
return;
4738
}
4839
var orgId = Array.isArray(orgIds) ? orgIds[0] : orgIds;
4940

@@ -63,24 +54,22 @@ KT.hosts.refreshContentViewEnvironments = function() {
6354
$.get(url, params, function(data) {
6455
var foundPreviousValue = false;
6556

66-
// Add inherit option back if it was there
67-
if (previousInheritText && (previousInheritText.includes('Inherit') || previousInheritText === '')) {
57+
if (inheritOption.length && (inheritOption.val() === '' || previousInheritDataId)) {
6858
var inheritOpt = $("<option />").text(previousInheritText).val('');
6959
if (previousInheritDataId) inheritOpt.attr('data-id', previousInheritDataId);
7060
select.append(inheritOpt);
7161
}
7262

73-
$.each(data.results, function(index, cve) {
74-
var label = cve.lifecycle_environment.name + ' / ' + cve.content_view.name;
75-
var option = $("<option />").val(cve.id).text(label);
76-
if (cve.id === parseInt(previousValue)) {
63+
$.each(data.results, function(index, cvEnv) {
64+
var label = cvEnv.label;
65+
var option = $("<option />").val(cvEnv.id).text(label);
66+
if (cvEnv.id === parseInt(previousValue)) {
7767
option.prop('selected', true);
7868
foundPreviousValue = true;
7969
}
8070
select.append(option);
8171
});
8272

83-
// If previous value not found in filtered list, select the blank/inherit option
8473
if (!foundPreviousValue) {
8574
select.val('');
8675
}
@@ -89,126 +78,9 @@ KT.hosts.refreshContentViewEnvironments = function() {
8978
});
9079
};
9180

92-
KT.hosts.fetchEnvironments = function () {
93-
var select = KT.hosts.getEnvironmentSelect();
94-
var content_source_id = $('#content_source_id').val();
95-
var option;
96-
select.find('option').remove();
97-
if (content_source_id) {
98-
var url = tfm.tools.foremanUrl('/katello/api/capsules/' + content_source_id);
99-
var orgIdsElem = $("#hostgroup_organization_ids");
100-
var orgIds = orgIdsElem.val();
101-
if (orgIds === undefined || orgIds === null || orgIds.length === 0) {
102-
orgIds = orgIdsElem.data('useds');
103-
}
104-
if (orgIds === undefined || orgIds === null || orgIds.length === 0) {
105-
orgIds = [$("#host_organization_id").val()];
106-
};
107-
orgIds = orgIds.map(function (id) {
108-
return Number(id);
109-
});
110-
$.get(url, function (content_source) {
111-
$.each(content_source.lifecycle_environments, function(index, env) {
112-
// Don't show environments that aren't in the selected org. See jQuery.each() docs
113-
if (!orgIds.includes(env.organization_id)) return true;
114-
option = $("<option />").val(env.id).text(env.name);
115-
select.append(option);
116-
});
117-
select.trigger('change');
118-
});
119-
}
120-
};
121-
122-
KT.hosts.fetchContentViews = function () {
123-
var select = KT.hosts.getContentViewSelect();
124-
var envId = KT.hosts.getSelectedEnvironment();
125-
var option;
126-
var previous_view = KT.hosts.getSelectedContentView();
127-
var previousInheritViewText = select.find('option:first-child').text();
128-
select.find('option').remove();
129-
if (envId) {
130-
KT.hosts.signalContentViewFetch(true);
131-
var url = tfm.tools.foremanUrl('/katello/api/v2/content_views');
132-
$.get(url, {environment_id: envId, full_result: true}, function (data) {
133-
if ($('#hostgroup_parent_id').length > 0) {
134-
select.append($("<option />").text(previousInheritViewText).val(''));
135-
}
136-
$.each(data.results, function(index, view) {
137-
option = $("<option />").val(view.id).text(view.name);
138-
if (view.id === parseInt(previous_view)) {
139-
option.prop('selected', true);
140-
}
141-
select.append(option);
142-
});
143-
select.trigger('change');
144-
KT.hosts.signalContentViewFetch(false);
145-
});
146-
}
147-
};
148-
149-
KT.hosts.signalContentViewFetch = function(fetching) {
150-
var select = KT.hosts.getContentViewSelect();
151-
var select2 = KT.hosts.getContentViewSelect2();
152-
spinner = $('<img>').attr('src', select.data("spinner-path")),
153-
spinner_id = "content_view_spinner";
154-
155-
if(fetching) {
156-
select.hide();
157-
select2.hide();
158-
$(spinner).attr('id', spinner_id).insertAfter(select);
159-
} else {
160-
select2.show();
161-
$('#' + spinner_id).remove();
162-
}
163-
};
164-
165-
KT.hosts.getContentViewSelect2 = function() {
166-
var select = $("#s2id_host_content_view_id").first();
167-
if(select.length === 0) {
168-
select = $("#s2id_hostgroup_content_view_id").first();
169-
}
170-
return select;
171-
};
172-
173-
KT.hosts.getContentViewSelect = function() {
174-
var select = $("#host_content_view_id").first();
175-
if(select.length === 0) {
176-
select = $("#hostgroup_content_view_id").first();
177-
}
178-
return select;
179-
};
180-
181-
KT.hosts.getSelectedContentView = function() {
182-
var select = KT.hosts.getContentViewSelect();
183-
return select.val() || select.find("option:selected").data("id");
184-
};
185-
186-
KT.hosts.getEnvironmentSelect = function() {
187-
var select = $("#hostgroup_lifecycle_environment_id").first();
188-
if(select.length === 0) {
189-
select = $("#host_lifecycle_environment_id").first();
190-
}
191-
return select;
192-
};
193-
194-
KT.hosts.getSelectedEnvironment = function () {
195-
var envId = $("#hostgroup_lifecycle_environment_id").val();
196-
if(envId === undefined || envId === null || envId.length === 0) {
197-
envId = $("#host_lifecycle_environment_id").val()
198-
}
199-
if(envId === undefined || envId === null || envId.length === 0) {
200-
envId = $("#hostgroup_lifecycle_environment_id > option:selected").data("id");
201-
}
202-
203-
if(envId && envId.length === 0) {
204-
envId = undefined;
205-
}
206-
return envId;
207-
};
208-
20981
KT.hosts.onKatelloHostEditLoad = function(){
21082
var prefixes = ['host', 'hostgroup'],
211-
attributes = ['content_view_id', 'environment_id', 'architecture_id'];
83+
attributes = ['content_view_environment_id', 'architecture_id'];
21284

21385
$('body').off('.hostsContentSourceNS');
21486

@@ -226,26 +98,38 @@ KT.hosts.onKatelloHostEditLoad = function(){
22698
});
22799
};
228100

229-
KT.hosts.toggle_installation_medium = function(content_view_id) {
230-
var lifecycle_environment_id, content_source_id, architecture_id, operatingsystem_id;
231-
232-
if (content_view_id === undefined) {
233-
content_view_id = KT.hosts.getSelectedContentView();
101+
KT.hosts.getSelectedContentViewEnvironment = function() {
102+
var cvEnvId = $("#hostgroup_content_view_environment_id").val();
103+
if (!cvEnvId) {
104+
cvEnvId = $("#host_content_view_environment_id").val();
105+
}
106+
if (!cvEnvId) {
107+
cvEnvId = $("#hostgroup_content_view_environment_id > option:selected").data("id");
108+
}
109+
if (!cvEnvId) {
110+
var hiddenInput = $("input[name='host[content_facet_attributes][content_view_environment_ids][]']").first();
111+
if (hiddenInput.length) {
112+
cvEnvId = hiddenInput.val();
113+
}
234114
}
115+
return cvEnvId;
116+
};
117+
118+
KT.hosts.toggle_installation_medium = function() {
119+
var content_view_environment_id, content_source_id, architecture_id, operatingsystem_id;
120+
121+
content_view_environment_id = KT.hosts.getSelectedContentViewEnvironment();
122+
content_source_id = $('#content_source_id').val();
235123

236124
if ($('#hostgroup_operatingsystem_id').data('type') == 'hostgroup') {
237-
lifecycle_environment_id = KT.hosts.getSelectedEnvironment();
238-
content_source_id = $('#content_source_id').val();
239125
architecture_id = $('#hostgroup_architecture_id').val();
240126
operatingsystem_id = $('#hostgroup_operatingsystem_id').val();
241127
} else {
242-
lifecycle_environment_id = KT.hosts.getSelectedEnvironment();
243-
content_source_id = $('#content_source_id').val();
244128
architecture_id = $('#host_architecture_id').val();
245129
operatingsystem_id = $('#host_operatingsystem_id').val();
246130
}
247131

248-
if (content_view_id && lifecycle_environment_id && content_source_id && architecture_id && operatingsystem_id) {
132+
if (content_view_environment_id && content_source_id && architecture_id && operatingsystem_id) {
249133
os_selected(KT.hosts.get_os_element());
250134
}
251135
};
@@ -318,13 +202,11 @@ KT.hosts.get_synced_content_dropdown = function() {
318202
};
319203

320204
KT.hosts.on_install_media_dropdown_change = function() {
321-
// reset the kickstart-repository-id .. They are either or.
322205
KT.hosts.get_synced_content_dropdown().val("");
323206
activate_select2("#media_select");
324207
};
325208

326209
KT.hosts.on_synced_content_dropdown_change = function() {
327-
// reset the kickstart-repository-id .. They are either or.
328210
$("#host_medium_id").val("");
329211
$("#s2id_host_medium_id").val("");
330212
$("#hostgroup_medium_id").val("");
@@ -333,7 +215,6 @@ KT.hosts.on_synced_content_dropdown_change = function() {
333215
};
334216

335217
KT.hosts.set_install_media_bindings = function() {
336-
// reset the host medium id
337218
$("#host_medium_id").on("select2:select", KT.hosts.on_install_media_dropdown_change);
338219
$("#s2id_host_medium_id").on("select2:select", KT.hosts.on_install_media_dropdown_change);
339220
$("#hostgroup_medium_id").on("select2:select", KT.hosts.on_install_media_dropdown_change);

app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,13 +427,13 @@ def update_environments_from_facts(param_environments)
427427
end
428428

429429
def get_content_view_environment(key, value)
430-
cve = nil
430+
cvenv = nil
431431
if value
432-
cve = ContentViewEnvironment.where(key => value).first
433-
fail HttpErrors::NotFound, _("Couldn't find environment '%s'") % value unless cve
434-
deny_access unless cve.readable? || User.consumer?
432+
cvenv = ContentViewEnvironment.where(key => value).first
433+
fail HttpErrors::NotFound, _("Couldn't find environment '%s'") % value unless cvenv
434+
deny_access unless cvenv.readable? || User.consumer?
435435
end
436-
cve
436+
cvenv
437437
end
438438

439439
def get_content_view_environments(label = nil, organization = nil)

0 commit comments

Comments
 (0)