[PATCH/foreman 1/1] fixes #1187 remove unrequired menus when foreman is not used for provisioning

this includes URLS, setting menu items and buttons.

Signed-off-by: Ohad Levy <ohadlevy@gmail.com>

··· --- app/helpers/hosts_helper.rb | 2 +- app/views/home/_settings.html.erb | 39 ++++++++++++++++++++---------------- app/views/hosts/edit.html.erb | 7 ++++- config/initializers/foreman.rb | 8 +++++- config/routes.rb | 30 +++++++++++++++++----------- 5 files changed, 52 insertions(+), 34 deletions(-)

diff --git a/app/helpers/hosts_helper.rb b/app/helpers/hosts_helper.rb
index f3ffc65…8de11a1 100644
— a/app/helpers/hosts_helper.rb
+++ b/app/helpers/hosts_helper.rb
@@ -42,7 +42,7 @@ module HostsHelper
[‘Change Group’, select_multiple_hostgroup_hosts_path],
[‘Change Environment’, select_multiple_environment_hosts_path],
[‘Edit Parameters’, multiple_parameters_hosts_path],

  •    ['Destroy Hosts', multiple_destroy_hosts_path],
    
  •    ['Delete Hosts', multiple_destroy_hosts_path],
       ['Disable Notifications', multiple_disable_hosts_path],
       ['Enable Notifications', multiple_enable_hosts_path],
    
    ]
    diff --git a/app/views/home/_settings.html.erb b/app/views/home/_settings.html.erb
    index 49411bb…0295463 100644
    — a/app/views/home/_settings.html.erb
    +++ b/app/views/home/_settings.html.erb
    @@ -1,23 +1,28 @@
Settings ▼
  • <% choices = []
  • choices += [['Architectures',          :architectures]]
    
  • choices += [['Bookmarks',              :bookmarks]]
    
  • choices += [['Domains',                :domains]]
    
  • choices += [['Environments',           :environments]]
    
  • choices += [['Foreman Settings',       :settings]]
    
  • choices += [['Global Parameters',      :common_parameters]]
    
  • choices += [['Hardware Models',        :models]]
    
  • choices += [['Host Groups',            :hostgroups]]
    
  • choices += [['Installation Media',     :media]]
    
  • choices += [['LDAP Authentication',    :auth_source_ldaps]]
    
  • choices += [['Operating Systems',      :operatingsystems]]
    
  • choices += [['Partition Tables',       :ptables]]
    
  • choices += [['Provisioning Templates', :config_templates]]
    
  • choices += [['Puppet Classes',         :puppetclasses]]
    
  • choices += [['Smart Proxies',          :smart_proxies]]
    
  • choices += [['Subnets',                :subnets]]
    
  • <%

  • choices = [

  •  ['Bookmarks',              :bookmarks],
    
  •  ['Environments',           :environments],
    
  •  ['Foreman Settings',       :settings],
    
  •  ['Global Parameters',      :common_parameters],
    
  •  ['Host Groups',            :hostgroups],
    
  •  ['LDAP Authentication',    :auth_source_ldaps],
    
  •  ['Puppet Classes',         :puppetclasses],
    
  •  ['Smart Proxies',          :smart_proxies]
    
  • ]

  • choices += [

  •  ['Architectures',          :architectures],
    
  •  ['Domains',                :domains],
    
  •  ['Hardware Models',        :models],
    
  •  ['Installation Media',     :media],
    
  •  ['Operating Systems',      :operatingsystems],
    
  •  ['Partition Tables',       :ptables],
    
  •  ['Provisioning Templates', :config_templates],
    
  •  ['Subnets',                :subnets]
    
  • ] if SETTINGS[:unattended]

    choices += [
    [‘Users’, :users],
    diff --git a/app/views/hosts/edit.html.erb b/app/views/hosts/edit.html.erb
    index 9206a46…8761ad5 100644
    — a/app/views/hosts/edit.html.erb
    +++ b/app/views/hosts/edit.html.erb
    @@ -2,7 +2,10 @@

    <%= link_to “Show”, @host %>
    <%= link_to “View All”, hosts_path %>

  • <%= display_link_if_authorized (@host.managed? ? “Unmanage host” : “Manage host”), hash_for_toggle_manage_host_path(:id => @host.name), {:method => :put} %>
  • <% if SETTINGS[:unattended] -%>
  • <%= display_link_if_authorized (@host.managed? ? “Unmanage host” : “Manage host”),
  •  hash_for_toggle_manage_host_path(:id => @host.name), {:method => :put} %>
    
  • <% end -%>

-<%= render :partial => ‘form’ %>
\ No newline at end of file
+<%= render :partial => ‘form’ %>
diff --git a/config/initializers/foreman.rb b/config/initializers/foreman.rb
index 6c1d805…3a11d6f 100644
— a/config/initializers/foreman.rb
+++ b/config/initializers/foreman.rb
@@ -15,8 +15,12 @@ $puppet = Puppet.settings.instance_variable_get(:@values) if Rails.env == "test"
SETTINGS[:login] ||= SETTINGS[:ldap]

begin

  • require ‘virt’
  • SETTINGS[:libvirt] = true
  • if SETTINGS[:unattended]
  • require ‘virt’
  • SETTINGS[:libvirt] = true
  • else
  • SETTINGS[:libvirt] = false
  • end
    rescue LoadError
    RAILS_DEFAULT_LOGGER.debug "Libvirt binding are missing - hypervisor management is disabled"
    SETTINGS[:libvirt] = false
    diff --git a/config/routes.rb b/config/routes.rb
    index b526fd8…e2ae8d5 100644
    — a/config/routes.rb
    +++ b/config/routes.rb
    @@ -27,12 +27,24 @@ ActionController::Routing::Routes.draw do |map|
    map.statistics ‘/statistics’, :controller => 'statistics’
    map.resources :notices, :only => :destroy
    map.resources :audits, :collection => {:auto_complete_search => :get}
  • map.resources :usergroups
  • map.resources :domains, :requirements => {:id => /[^/]+/}, :collection => {:auto_complete_search => :get}
  • map.resources :operatingsystems, :member => {:bootfiles => :get}, :collection => {:auto_complete_search => :get}
  • map.resources :media, :collection => {:auto_complete_search => :get}
  • map.resources :models, :collection => {:auto_complete_search => :get}
  • map.resources :architectures, :collection => {:auto_complete_search => :get}
  • if SETTINGS[:login]
  • map.resources :usergroups
  • map.resources :users, :collection => {:login => [:get, :post], :logout => :get, :auth_source_selected => :get, :auto_complete_search => :get}
  • map.resources :roles, :collection => {:report => [:get, :post], :auto_complete_search => :get}
  • end
  • if SETTINGS[:unattended]
  • map.resources :domains, :requirements => {:id => /[^/]+/}, :collection => {:auto_complete_search => :get}
  • map.resources :operatingsystems, :member => {:bootfiles => :get}, :collection => {:auto_complete_search => :get}
  • map.resources :media, :collection => {:auto_complete_search => :get}
  • map.resources :models, :collection => {:auto_complete_search => :get}
  • map.resources :architectures, :collection => {:auto_complete_search => :get}
  • map.resources :ptables, :collection => {:auto_complete_search => :get}
  • map.resources :config_templates, :except => [:show], :collection => { :auto_complete_search => :get }, :requirements => { :id => /[^/]+/ }
  • map.resources :subnets, :except => [:show], :collection => {:auto_complete_search => :get}
  • map.connect ‘unattended/template/:id/:hostgroup’, :controller => “unattended”, :action => “template”
  • end
  • map.resources :lookup_keys, :except => [:new, :create], :requirements => {:id => /[^/]+/} do |keys|
    keys.resources :lookup_values, :only => [:index, :create, :update, :destroy]
    end
    @@ -47,23 +59,17 @@ ActionController::Routing::Routes.draw do |map|
    map.resources :facts, :only => [:index, :show], :requirements => {:id => /[^/]+/} do |facts|
    facts.resources :values, :requirements => {:id => /[^/]+/}, :only => :index, :controller => :fact_values
    end
  • map.resources :ptables, :collection => {:auto_complete_search => :get}

  • map.resources :roles, :collection => {:report => [:get, :post], :auto_complete_search => :get}
    map.resources :auth_source_ldaps

  • map.resources :users, :collection => {:login => [:get, :post], :logout => :get, :auth_source_selected => :get, :auto_complete_search => :get}

  • map.resources :config_templates, :except => [:show], :collection => { :auto_complete_search => :get }, :requirements => { :id => /[^/]+/ }
    map.resources :smart_proxies, :except => [:show] do |proxy|
    proxy.resources :puppetca, :controller => “SmartProxies::Puppetca”, :only => [:index, :update, :destroy], :requirements => { :id => /[^.][\w.-]+/ }
    proxy.resources :autosign, :controller => “SmartProxies::Autosign”, :only => [:index, :new, :create, :destroy], :requirements => { :id => /[^.][\w.-]+/ }
    end

  • map.resources :subnets, :except => [:show], :collection => {:auto_complete_search => :get}
    map.resources :hypervisors, :requirements => { :id => /[^/]+/ } do |hypervisor|
    hypervisor.resources :guests, :controller => “Hypervisors::Guests”, :except => [:edit],
    :member => {:power => :put}, :requirements => { :id => /[^.][\w.-]+/ }
    end if SETTINGS[:libvirt]
    map.resources :bookmarks, :except => [:show], :requirements => { :id => /[^/]+/ }
    map.resources :settings, :only => [:index, :update]

  • map.connect ‘unattended/template/:id/:hostgroup’, :controller => “unattended”, :action => "template"
    map.connect ‘/status’, :controller => “home”, :action => “status”

    #default

    1.7.6.2