Skip to content

Commit

Permalink
Fixes #37544 - properly access host for hostgroup inheritance checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ianballou committed Jun 24, 2024
1 parent fc3dff1 commit 16440c3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
16 changes: 8 additions & 8 deletions app/helpers/katello/hosts_and_hostgroups_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ def cv_lce_disabled?
edit_action? && !using_discovered_hosts_page?
end

def content_source_inherited?
!using_hostgroups_page? && @host.content_source.blank? && @host&.hostgroup&.content_source.present? && cv_lce_disabled?
def content_source_inherited?(host)
!using_hostgroups_page? && host&.content_source.blank? && host&.hostgroup&.content_source.present? && cv_lce_disabled?
end

def lifecycle_environment_inherited?
!using_hostgroups_page? && @host.lifecycle_environments.empty? && @host&.hostgroup&.lifecycle_environment.present? && cv_lce_disabled?
def lifecycle_environment_inherited?(host)
!using_hostgroups_page? && host&.lifecycle_environments&.empty? && host&.hostgroup&.lifecycle_environment.present? && cv_lce_disabled?
end

def content_view_inherited?
!using_hostgroups_page? && @host.content_views.empty? && @host&.hostgroup&.content_view.present? && cv_lce_disabled?
def content_view_inherited?(host)
!using_hostgroups_page? && host&.content_views&.empty? && host&.hostgroup&.content_view.present? && cv_lce_disabled?
end

def kickstart_repo_inherited?
!using_hostgroups_page? && @host.kickstart_repository_id.blank? && @host&.hostgroup&.kickstart_repository.present? && cv_lce_disabled?
def kickstart_repo_inheritable?(host)
host&.kickstart_repository_id.blank?
end

def using_discovered_hosts_page?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<% cs_select_name = using_hostgroups_page? ? 'hostgroup[content_source_id]' : 'host[content_facet_attributes][content_source_id]' %>
<% cs_select_attr = using_hostgroups_page? ? 'content_source' : 'content_facet.content_source' %>
<%= field(f, cs_select_attr, {:label => _("Content Source"), :help_inline => content_source_inherited? ? 'Inherited' : nil }) do %>
<%= field(f, cs_select_attr, {:label => _("Content Source"), :help_inline => content_source_inherited?(@host) ? 'Inherited from host group' : nil }) do %>
<% if using_hostgroups_page? %>
<%= select_tag cs_select_id, content_source_options(@hostgroup, :include_blank => blank_or_inherit_with_id(f, :content_source)), :data => {"spinner_path" => spinner_path},
:class => 'form-control', :name => cs_select_name %>
Expand All @@ -29,17 +29,13 @@
<% env_select_name = using_hostgroups_page? ? 'hostgroup[lifecycle_environment_id]' : 'host[content_facet_attributes][lifecycle_environment_id]' %>
<% env_select_attr = using_hostgroups_page? ? 'lifecycle_environment' : 'content_facet.single_lifecycle_environment' %>
<%= field(f, env_select_attr, {:label => _("Lifecycle Environment"), :help_inline => lifecycle_environment_inherited? ? 'Inherited' : nil}) do %>
<%= field(f, env_select_attr, {:label => _("Lifecycle Environment"), :help_inline => lifecycle_environment_inherited?(@host) ? 'Inherited from host group' : nil}) do %>
<% if using_hostgroups_page? %>
<%= select_tag env_select_id, lifecycle_environment_options(@hostgroup, :include_blank => blank_or_inherit_with_id(f, :lifecycle_environment)), :class => 'form-control', :name => env_select_name %>
<% elsif cv_lce_disabled? %>
<% host_or_hostgroup_lce = (@host.lifecycle_environments.empty? && @host.hostgroup.present? && @host.hostgroup.lifecycle_environment.present?) ? fetch_lifecycle_environment(@host.hostgroup) : fetch_lifecycle_environment(@host) %>
<%= hidden_field_tag 'host[content_facet_attributes][lifecycle_environment_id]', host_or_hostgroup_lce.try(:id) %>
<% if @host&.hostgroup&.lifecycle_environment.present? %>
<%= select_tag env_select_id, lifecycle_environment_options(@host, :selected_host_group => @hostgroup || @host.hostgroup, :include_blank => blank_or_inherit_with_id(f, :lifecycle_environment)), :class => 'form-control', :name => env_select_name, :disabled => true %>
<% else %>
<%= select_tag env_select_id, '<option></option>', :class => 'form-control', :name => env_select_name, :disabled => true %>
<% end %>
<%= select_tag env_select_id, lifecycle_environment_options(@host, :selected_host_group => @hostgroup || @host.hostgroup, :include_blank => blank_or_inherit_with_id(f, :lifecycle_environment)), :class => 'form-control', :name => env_select_name, :disabled => true %>
<% else %>
<%= select_tag env_select_id, lifecycle_environment_options(@host, :selected_host_group => @hostgroup || @host.hostgroup, :include_blank => blank_or_inherit_with_id(f, :lifecycle_environment)), :class => 'form-control', :name => env_select_name %>
<% end %>
Expand All @@ -49,7 +45,7 @@
<% cv_select_name = using_hostgroups_page? ? 'hostgroup[content_view_id]' : 'host[content_facet_attributes][content_view_id]' %>
<% cv_select_attr = using_hostgroups_page? ? 'content_view' : 'content_facet.single_content_view' %>
<%= field(f, cv_select_attr, {:label => _("Content View"), :help_inline => content_view_inherited? ? 'Inherited' : nil}) do %>
<%= field(f, cv_select_attr, {:label => _("Content View"), :help_inline => content_view_inherited?(@host) ? 'Inherited from host group' : nil}) do %>
<% if using_hostgroups_page? %>
<%= select_tag cv_select_id, content_views_for_host(@hostgroup, :include_blank => blank_or_inherit_with_id(f, :content_view)), :data => {"spinner_path" => spinner_path}, :class => 'form-control', :name => cv_select_name %>
<% elsif cv_lce_disabled? %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<% spinner_path = asset_path('spinner.gif') %>
<%= field(f, ks_repo_select_attr, {:label => _("Synced Content"), :help_inline => kickstart_repo_inherited? ? 'Inherited' : nil}) do %>
<%= field(f, ks_repo_select_attr, {:label => _("Synced Content"), :help_inline => kickstart_repo_inheritable?(@host) ? 'Automatically selected from content source, lifecycle environment, content_view, architecture, and operating system' : nil}) do %>
<%= select_tag ks_repo_select_id, view_to_options(kickstart_options, kickstart_repo_id, blank_or_inherit_with_id(f, :kickstart_repository)), :data => {"spinner_path" => spinner_path, "kickstart-repository-id" => kickstart_repo_id},
:class => 'form-control', :name => ks_repo_select_name, :disabled => kickstart_options.empty? %>
<% end %>
Expand Down

0 comments on commit 16440c3

Please sign in to comment.