Skip to content

Commit

Permalink
Fixes #30913 - drop environment field from Host(group) form
Browse files Browse the repository at this point in the history
Drops the environment field and all js attached to it.

Extracted in theforeman/foreman_puppet#64.
  • Loading branch information
ezr-ondrej authored and kamils-iRonin committed Apr 20, 2021
1 parent 7fe9124 commit f0fd12d
Show file tree
Hide file tree
Showing 23 changed files with 76 additions and 818 deletions.
29 changes: 0 additions & 29 deletions app/assets/javascripts/application.js
Expand Up @@ -328,35 +328,6 @@ $(function() {
});
});

function update_puppetclasses(element) {
var host_id = $('form').data('id');
var url = $(element).attr('data-url');
var data = serializeForm().replace('method=patch', 'method=post');

if (element.value == '') return;
if (url.match('hostgroups')) {
data = data + '&hostgroup_id=' + host_id;
} else {
data = data + '&host_id=' + host_id;
}

tfm.tools.showSpinner();
$.ajax({
type: 'post',
url: url,
data: data,
success: function(request) {
$('#puppet_klasses').html(request);
reload_puppetclass_params();
tfm.tools.activateTooltips();
tfm.hostgroups.checkForUnavailablePuppetclasses();
},
complete: function() {
reloadOnAjaxComplete(element);
},
});
}

function spinner_placeholder(text) {
if (text == undefined) text = '';
return (
Expand Down
57 changes: 0 additions & 57 deletions app/assets/javascripts/host_edit.js
Expand Up @@ -3,9 +3,6 @@
$(document).on('ContentLoad', function() {
onHostEditLoad();
});
$(document).on('AddedClass', function(event, link) {
load_puppet_class_parameters(link);
});
$(document)
.on('change', '.hostgroup-select', function(evt) {
hostgroup_changed(evt.target);
Expand Down Expand Up @@ -238,44 +235,6 @@ function update_progress(data) {
$('#tasks_progress').replaceWith(data);
}

function load_puppet_class_parameters(item) {
var id = $(item).attr('data-class-id');
// host_id could be either host.id OR hostgroup.id depending on which form
var host_id = $('form').data('id');
if ($('#puppetclass_' + id + '_params_loading').length > 0) return; // already loading
if ($('[id^="#puppetclass_' + id + '_params\\["]').length > 0) return; // already loaded
var url = $(item).attr('data-url');
var data = serializeForm().replace('method=patch', 'method=post');
if (url.match('hostgroups')) {
data = data + '&hostgroup_id=' + host_id;
} else {
data = data + '&host_id=' + host_id;
}

if (url == undefined) return; // no parameters
var placeholder = $(
'<tr id="puppetclass_' +
id +
'_params_loading">' +
'<td colspan="5">' +
spinner_placeholder(__('Loading parameters...')) +
'</td></tr>'
);
$('#inherited_puppetclasses_parameters').append(placeholder);
$.ajax({
url: url,
type: 'post',
data: data,
success: function(result, textstatus, xhr) {
var params = $(result);
placeholder.replaceWith(params);
params.find('a[rel="popover"]').popover();
if (params.find('.error').length > 0)
$('#params-tab').addClass('tab-error');
},
});
}

function hostgroup_changed(element) {
var host_id = $('form').data('id');
var host_changed = $('form').data('type-changed');
Expand All @@ -296,7 +255,6 @@ function handleHostgroupChangeEdit(element, host_id, host_changed) {
} else {
// edit host
set_inherited_value(element);
update_puppetclasses(element);
reload_host_params();
}
}
Expand Down Expand Up @@ -431,7 +389,6 @@ function os_selected(element) {
success: function(request) {
$('#media_select').html(request);
reload_host_params();
reload_puppetclass_params();
},
});
update_provisioning_image();
Expand Down Expand Up @@ -525,18 +482,6 @@ function reload_host_params() {
}
}

function reload_puppetclass_params() {
var host_id = $('form.hostresource-form').data('id');
var url2 = $('#params-tab').data('url2');
var data = serializeForm().replace('method=patch', 'method=post');
if (url2.match('hostgroups')) {
data = data + '&hostgroup_id=' + host_id;
} else {
data = data + '&host_id=' + host_id;
}
load_with_placeholder('inherited_puppetclasses_parameters', url2, data);
}

function load_with_placeholder(target, url, data) {
if (url == undefined) return;
var placeholder = $(
Expand All @@ -561,7 +506,6 @@ function load_with_placeholder(target, url, data) {

function onHostEditLoad() {
update_interface_table();
tfm.hostgroups.checkForUnavailablePuppetclasses();

$('#host-conflicts-modal').modal({ show: 'true', backdrop: 'static' });
$('#host-conflicts-modal').click(function() {
Expand Down Expand Up @@ -636,7 +580,6 @@ $(document).on('change', '.interface_domain', function() {
);
interface_domain_selected(this);
reload_host_params();
reload_puppetclass_params();
});

function clearIpField(parent, childclass) {
Expand Down
Expand Up @@ -2,17 +2,13 @@ module Foreman::Controller::Puppet::HostsControllerExtensions
extend ActiveSupport::Concern

PUPPETMASTER_ACTIONS = [:externalNodes, :lookup]
PUPPET_AJAX_REQUESTS = %w{hostgroup_or_environment_selected puppetclass_parameters}

MULTIPLE_EDIT_ACTIONS = %w(select_multiple_puppet_proxy update_multiple_puppet_proxy
select_multiple_puppet_ca_proxy update_multiple_puppet_ca_proxy)

included do
add_smart_proxy_filters PUPPETMASTER_ACTIONS, :features => ['Puppet']
alias_method :ajax_request_for_puppet_host_extensions, :ajax_request

before_action :ajax_request_for_puppet_host_extensions, :only => PUPPET_AJAX_REQUESTS
before_action :taxonomy_scope_for_puppet_host_extensions, :only => PUPPET_AJAX_REQUESTS
before_action :find_multiple_for_puppet_host_extensions, :only => MULTIPLE_EDIT_ACTIONS
before_action :validate_multiple_puppet_proxy, :only => :update_multiple_puppet_proxy
before_action :validate_multiple_puppet_ca_proxy, :only => :update_multiple_puppet_ca_proxy
Expand All @@ -22,24 +18,6 @@ module Foreman::Controller::Puppet::HostsControllerExtensions
set_callback :set_class_variables, :after, :set_puppet_class_variables
end

def hostgroup_or_environment_selected
refresh_host
set_class_variables(@host)
Taxonomy.as_taxonomy @organization, @location do
if @environment || @hostgroup
render :partial => 'puppetclasses/class_selection', :locals => {:obj => @host}
else
logger.info "environment_id or hostgroup_id is required to render puppetclasses"
end
end
end

def puppetclass_parameters
Taxonomy.as_taxonomy @organization, @location do
render :partial => "puppetclasses/classes_parameters", :locals => { :obj => refresh_host}
end
end

def validate_multiple_puppet_proxy
validate_multiple_proxy(select_multiple_puppet_proxy_hosts_path)
end
Expand Down Expand Up @@ -127,10 +105,6 @@ def set_puppet_class_variables
@environment = @host.environment
end

def taxonomy_scope_for_puppet_host_extensions
taxonomy_scope
end

def find_multiple_for_puppet_host_extensions
find_multiple
end
Expand Down
21 changes: 1 addition & 20 deletions app/controllers/hostgroups_controller.rb
Expand Up @@ -6,7 +6,7 @@ class HostgroupsController < ApplicationController
include Foreman::Controller::SetRedirectionPath

before_action :find_resource, :only => [:nest, :clone, :edit, :update, :destroy]
before_action :ajax_request, :only => [:process_hostgroup, :puppetclass_parameters]
before_action :ajax_request, :only => [:process_hostgroup]
before_action :taxonomy_scope, :only => [:new, :edit, :process_hostgroup]

def index
Expand Down Expand Up @@ -83,25 +83,6 @@ def destroy
process_error(:error_msg => _("Cannot delete group %{current} because it has nested groups.") % { :current => @hostgroup.title })
end

def puppetclass_parameters
Taxonomy.as_taxonomy @organization, @location do
render :partial => "puppetclasses/classes_parameters",
:locals => { :obj => refresh_hostgroup }
end
end

def environment_selected
env_id = params[:environment_id] || params[:hostgroup][:environment_id]
return not_found if env_id.to_i > 0 && !(@environment = Environment.find(env_id))

refresh_hostgroup
@hostgroup.environment = @environment if @environment

@hostgroup.puppetclasses = Puppetclass.where(:id => params[:hostgroup][:puppetclass_ids])
@hostgroup.config_groups = ConfigGroup.where(:id => params[:hostgroup][:config_group_ids])
render :partial => 'puppetclasses/class_selection', :locals => {:obj => @hostgroup, :type => 'hostgroup'}
end

def process_hostgroup
define_parent
refresh_hostgroup
Expand Down
62 changes: 0 additions & 62 deletions app/helpers/puppet_related_helper.rb
Expand Up @@ -5,68 +5,6 @@ module PuppetRelatedHelper
overview_buttons_provider :puppet_host_overview_buttons
end

def host_puppet_environment_field(form, select_options = {}, html_options = {})
select_options = {
:include_blank => true,
:disable_button => _(HostsAndHostgroupsHelper::INHERIT_TEXT),
:disable_button_enabled => inherited_by_default?(:environment_id, @host),
:user_set => user_set?(:environment_id)}.deep_merge(select_options)

html_options = {
:data => {
:url => hostgroup_or_environment_selected_hosts_path,
:host => {
:id => @host.id,
},
}}.deep_merge(html_options)

puppet_environment_field(
form,
accessible_resource(@host, :environment),
select_options,
html_options)
end

def hostgroup_puppet_environment_field(form, select_options = {}, html_options = {})
select_options = {
:include_blank => blank_or_inherit_f(form, :environment),
}.deep_merge(select_options)

html_options = {
:data => {
:url => environment_selected_hostgroups_path,
}}.deep_merge(html_options)

puppet_environment_field(
form,
accessible_resource(@hostgroup, :environment),
select_options,
html_options)
end

def puppet_environment_field(form, environments_choice, select_options = {}, html_options = {})
html_options = {
:onchange => "update_puppetclasses(this)",
:help_inline => :indicator}.deep_merge(html_options)

select_f(
form,
:environment_id,
environments_choice,
:id,
:to_label,
select_options,
html_options)
end

def interesting_puppetclasses(obj)
classes = obj.all_puppetclasses
classes_ids = classes.reorder(nil).pluck("puppetclasses.id")
class_vars = PuppetclassLookupKey.reorder(nil).joins(:environment_classes).where(:environment_classes => { :puppetclass_id => classes_ids }).distinct.pluck("environment_classes.puppetclass_id")

classes.where(:id => class_vars)
end

def puppet_actions
actions = []
if authorized_for(:controller => :hosts, :action => :edit)
Expand Down
10 changes: 5 additions & 5 deletions app/registries/foreman/access_permissions.rb
Expand Up @@ -240,8 +240,8 @@
end

permission_set.security_block :hostgroups do |map|
ajax_actions = [:architecture_selected, :domain_selected, :environment_selected, :medium_selected, :os_selected,
:use_image_selected, :process_hostgroup, :puppetclass_parameters, :welcome]
ajax_actions = [:architecture_selected, :domain_selected, :medium_selected, :os_selected,
:use_image_selected, :process_hostgroup, :welcome]
host_ajax_actions = [:process_hostgroup]
pc_ajax_actions = [:parameters]

Expand Down Expand Up @@ -280,9 +280,9 @@
end

permission_set.security_block :hosts do |map|
ajax_actions = [:architecture_selected, :compute_resource_selected, :domain_selected, :environment_selected,
:hostgroup_or_environment_selected, :medium_selected, :os_selected, :use_image_selected, :process_hostgroup,
:process_taxonomy, :current_parameters, :puppetclass_parameters, :template_used, :interfaces, :scheduler_hint_selected,
ajax_actions = [:architecture_selected, :compute_resource_selected, :domain_selected,
:medium_selected, :os_selected, :use_image_selected, :process_hostgroup,
:process_taxonomy, :current_parameters, :template_used, :interfaces, :scheduler_hint_selected,
:random_name]
cr_ajax_actions = [:cluster_selected, :template_selected, :instance_type_selected, :provider_selected, :resource_pools]
pc_ajax_actions = [:parameters]
Expand Down
15 changes: 4 additions & 11 deletions app/views/hostgroups/_form.html.erb
@@ -1,5 +1,5 @@
<%= javascript 'host_edit', 'host_edit_interfaces' %>
<%= form_for @hostgroup, :html => {:class => 'hostresource-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)}} do |f| %>
<%= base_errors_for @hostgroup %>

<ul class="nav nav-tabs" data-tabs="tabs">
Expand All @@ -8,7 +8,7 @@
<li><a href="#network" data-toggle="tab"><%= _('Network') %></a></li>
<li><a href="#os" data-toggle="tab"><%= _('Operating System') %></a></li>
<% end %>
<li><a href="#params" id='params-tab' data-url='' data-url2='<%= puppetclass_parameters_hostgroups_path %>' data-toggle="tab"><%= _('Parameters') %></a></li>
<li><a href="#params" id='params-tab' data-url='' data-toggle="tab"><%= _('Parameters') %></a></li>
<%= render_tab_header_for(:main_tabs, :subject => @hostgroup) %>
<% if show_location_tab? %>
<li><a href="#locations" data-toggle="tab"><%= _('Locations') %></a></li>
Expand All @@ -27,7 +27,6 @@
:help_inline => :indicator }) if show_parent?(@hostgroup) %>
<%= text_f f, :name %>
<%= textarea_f f, :description, :rows => :auto %>
<%= hostgroup_puppet_environment_field f %>
<%= 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')) },
Expand All @@ -38,15 +37,15 @@
{ :include_blank => blank_or_inherit_f(f, :compute_profile) },
{ :label => _("Compute profile") }
) if visible_compute_profiles(@hostgroup).any? %>
<%= render_pagelets_for(:main_tab_fields, :hostgroup => @hostgroup, :form => f) %>
<%= render_pagelets_for(:main_tab_fields, :subject => @hostgroup, :form => f) %>
<%= smart_proxy_fields f %>
</div>

<div class="tab-pane" id="network">
<fieldset>
<%= select_f f, :domain_id, accessible_resource(@hostgroup, :domain), :id, :to_label, {:include_blank => blank_or_inherit_f(f, :domain)},
{:help_inline => :indicator, :label => _("Domain"),
:onchange => 'interface_domain_selected(this);', :'data-url' => method_path('domain_selected') } %>
:class => 'interface_domain', :'data-url' => method_path('domain_selected') } %>
<%= select_f f, :subnet_id, domain_subnets(:"Subnet::Ipv4"), :id, :to_label,
{ :include_blank => domain_subnets(:"Subnet::Ipv4").any? ? blank_or_inherit_f(f, :subnet) : _("No subnets") },
{ :disabled => domain_subnets(:"Subnet::Ipv4").empty?,
Expand All @@ -72,12 +71,6 @@

<div class="tab-pane" id="params">

<fieldset>
<h2><%= _('Puppet Class Parameters') %></h2>
<%= render 'puppetclasses/classes_parameters', :obj => @hostgroup %>
</fieldset>
<br/>

<%= slot('HostgroupParams', true, lookup_values: lookup_values_data(@hostgroup)) %>
<% if authorized_for(:controller => "host_editing", :action => "view_params") %>
Expand Down

0 comments on commit f0fd12d

Please sign in to comment.