Skip to content

Commit

Permalink
Fixes #37714 - inherit overrides deploy on in hostgroup
Browse files Browse the repository at this point in the history
  • Loading branch information
MariaAga committed Aug 14, 2024
1 parent f824a88 commit 36cd3ca
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 13 deletions.
10 changes: 10 additions & 0 deletions app/assets/javascripts/host_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ function update_capabilities(capabilities) {

var stop_pooling;

if (window.location.href.contains('hostgroup')) {
document.addEventListener('DOMContentLoaded', function() {
const form = document.querySelector('form');
form.addEventListener('submit', function() {
// // making sure inherited compute resource is included in the form
const hostgroup_compute_resource_id = $('#hostgroup_compute_resource_id');
hostgroup_compute_resource_id.prop('disabled', false);
});
});
}
function submit_with_all_params() {
$('form.hostresource-form input[type="submit"]').attr('disabled', true);
stop_pooling = false;
Expand Down
23 changes: 13 additions & 10 deletions app/controllers/hostgroups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def nest
@hostgroup = Hostgroup.new(:parent_id => @parent.id)

load_vars_for_ajax
@hostgroup.compute_resource_id = @parent.compute_resource_id
@hostgroup.locations = @parent.locations
@hostgroup.organizations = @parent.organizations
# Clone any parameters as well
Expand Down Expand Up @@ -101,11 +102,12 @@ def csv_columns
def load_vars_for_ajax
return unless @hostgroup.present?

@architecture = @hostgroup.architecture
@operatingsystem = @hostgroup.operatingsystem
@domain = @hostgroup.domain
@subnet = @hostgroup.subnet
@realm = @hostgroup.realm
@compute_resource_id = @hostgroup.compute_resource_id
@architecture = @hostgroup.architecture
@operatingsystem = @hostgroup.operatingsystem
@domain = @hostgroup.domain
@subnet = @hostgroup.subnet
@realm = @hostgroup.realm
end

def users_in_ancestors
Expand Down Expand Up @@ -144,11 +146,12 @@ def refresh_hostgroup
def inherit_parent_attributes
return unless @parent.present?

@hostgroup.architecture ||= @parent.architecture
@hostgroup.operatingsystem ||= @parent.operatingsystem
@hostgroup.domain ||= @parent.domain
@hostgroup.subnet ||= @parent.subnet
@hostgroup.realm ||= @parent.realm
@hostgroup.compute_resource_id ||= @parent.compute_resource_id
@hostgroup.architecture ||= @parent.architecture
@hostgroup.operatingsystem ||= @parent.operatingsystem
@hostgroup.domain ||= @parent.domain
@hostgroup.subnet ||= @parent.subnet
@hostgroup.realm ||= @parent.realm
end

def reset_explicit_attributes
Expand Down
15 changes: 15 additions & 0 deletions app/helpers/hostgroups_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,19 @@ def prioritized_members(list, value_key)
sort_by { |member| member[:priority] }.
map { |member_hash| member_hash[value_key] }
end

def hostgroup_inherited_by_default?(field, hostgroup)
return false if hostgroup.ancestry.nil?
return false if params[:action] == 'clone'
return true unless params[:hostgroup]
!params[:hostgroup][field]
end

def blank_or_inherit_hostgroup_f(f, attr, blank_value: _("no value"))
return true unless f.object.respond_to?(:parent_id) && f.object.parent_id
inherited_value = f.object.send(attr)
inherited_value = inherited_value.name_method if inherited_value.present? && inherited_value.respond_to?(:name_method)
inherited_value ||= blank_value
_("Inherit parent (%s)") % inherited_value
end
end
14 changes: 11 additions & 3 deletions app/views/hostgroups/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= javascript 'host_edit', 'host_edit_interfaces' %>
<%= form_for @hostgroup, :html => {:class => 'hostresource-form hostgroup-form form-horizontal well', :data => {:id => @hostgroup.try(:id)}} do |f| %>
<%= form_for @hostgroup, :html => {:class => 'hostresource-form hostgroup-form form-horizontal well', :data => {:id => @hostgroup.try(:id), :submit => 'progress_bar'}} do |f| %>
<%= base_errors_for @hostgroup %>

<ul class="nav nav-tabs" data-tabs="tabs">
Expand All @@ -26,8 +26,16 @@
<%= text_f f, :name %>
<%= textarea_f f, :description, :rows => :auto %>
<%= select_f f, :compute_resource_id, accessible_resource(@hostgroup, :compute_resource), :id, :to_label,
{ :include_blank => blank_or_inherit_f(f, :compute_resource, blank_value: _('Bare Metal')) },
<%= select_f f, :compute_resource_id,
accessible_resource(@hostgroup, :compute_resource),
:id,
:to_label,
{
:disable_button_enabled => hostgroup_inherited_by_default?(:compute_resource_id, @hostgroup),
:disable_button => _(HostsAndHostgroupsHelper::INHERIT_TEXT),
:user_set => user_set?(:compute_resource_id),
:include_blank => _('Bare Metal'),
},
{ :label => _('Deploy on'),
:help_inline => :indicator } %>
Expand Down

0 comments on commit 36cd3ca

Please sign in to comment.