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 committed Oct 26, 2020
1 parent 2ed777a commit 47e4bdb
Show file tree
Hide file tree
Showing 11 changed files with 8 additions and 244 deletions.
29 changes: 0 additions & 29 deletions app/assets/javascripts/application.js
Expand Up @@ -345,35 +345,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
14 changes: 0 additions & 14 deletions app/assets/javascripts/host_edit.js
Expand Up @@ -431,7 +431,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 +524,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 Down Expand Up @@ -636,7 +623,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,18 +2,14 @@ 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_environment update_multiple_environment
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 @@ -23,24 +19,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 select_multiple_environment
end

Expand Down Expand Up @@ -174,10 +152,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
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 @@ -71,12 +70,6 @@
</div>

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

<fieldset>
<h2><%= _('Puppet Class Parameters') %></h2>
<%= render 'puppetclasses/classes_parameters', :obj => @hostgroup %>
</fieldset>
<br/>
<% if authorized_for(:controller => "host_editing", :action => "view_params") %>
<fieldset>
<% if @hostgroup.parent.present? %>
Expand Down
11 changes: 3 additions & 8 deletions app/views/hosts/_form.html.erb
Expand Up @@ -4,7 +4,7 @@
<%= render "hosts/progress" %>
<% Taxonomy.as_taxonomy @organization , @location do %>
<%= form_for @host, :url => (@host.new_record? ? hosts_path : host_path(:id => @host.id)), :html => {:class => 'hostresource-form form-horizontal well', :data => {:id => @host.try(:id), :type_changed => !!@host.type_changed?, :submit => 'progress_bar'}} do |f| %>
<%= form_for @host, :url => (@host.new_record? ? hosts_path : host_path(:id => @host.id)), :html => {:class => 'hostresource-form host-form form-horizontal well', :data => {:id => @host.try(:id), :type_changed => !!@host.type_changed?, :submit => 'progress_bar'}} do |f| %>
<%= base_errors_for @host %>

<ul class="nav nav-tabs" data-tabs="tabs">
Expand All @@ -21,7 +21,7 @@

<%= render_tab_header_for(:main_tabs, :subject => @host) %>

<li><a href="#params" id='params-tab' data-url='<%= current_parameters_hosts_path %>' data-url2='<%= puppetclass_parameters_hosts_path %>' data-toggle="tab"><%= _('Parameters') %></a></li>
<li><a href="#params" id='params-tab' data-url='<%= current_parameters_hosts_path %>' data-toggle="tab"><%= _('Parameters') %></a></li>

<li><a href="#info" data-toggle="tab"><%= _('Additional Information') %></a></li>
</ul>
Expand Down Expand Up @@ -76,7 +76,7 @@
</div>
<% end %>
<%= render_pagelets_for(:main_tab_fields, :host => @host, :form => f) %>
<%= render_pagelets_for(:main_tab_fields, :subject => @host, :form => f) %>
<%= smart_proxy_fields f,
:can_override => true,
Expand Down Expand Up @@ -104,11 +104,6 @@
<%= render('hosts/unattended', :f => f) if SETTINGS[:unattended] and @host.managed %>
<div class="tab-pane" id="params">
<fieldset>
<h2><%= _('Puppet Class Parameters') %></h2>
<%= render "puppetclasses/classes_parameters", :obj => @host %>
</fieldset>
<br/>
<% if authorized_for(:controller => "host_editing", :action => "view_params") %>
<fieldset>
<h2><%= _('Global Parameters') %></h2>
Expand Down
1 change: 0 additions & 1 deletion app/views/hosts/puppet/_main_tab_fields.html.erb

This file was deleted.

16 changes: 0 additions & 16 deletions app/views/puppetclasses/_classes_parameters.html.erb

This file was deleted.

7 changes: 0 additions & 7 deletions config/initializers/puppet.rb
@@ -1,10 +1,3 @@
# initialize puppet related pagelets
Pagelets::Manager.with_key "hosts/_form" do |mgr|
mgr.add_pagelet :main_tab_fields,
:partial => "hosts/puppet/main_tab_fields",
:priority => 100
end

Foreman::Plugin.fact_importer_registry.register(:puppet, PuppetFactImporter, true)
FactParser.register_fact_parser :puppet, PuppetFactParser, true

Expand Down

0 comments on commit 47e4bdb

Please sign in to comment.