Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #35215 - Handle cloned hostgroups in hosts_and_hostgroups_helper #10894

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions app/helpers/katello/hosts_and_hostgroups_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,31 @@ def kickstart_repository_id(host, options = {})
def fetch_lifecycle_environment(host_or_hostgroup, options = {})
return host_or_hostgroup.single_lifecycle_environment if host_or_hostgroup.try(:single_lifecycle_environment)
return host_or_hostgroup.lifecycle_environment if host_or_hostgroup.try(:lifecycle_environment)
if host_or_hostgroup.is_a?(::Hostgroup) && host_or_hostgroup.content_facet.present?
# to handle cloned hostgroups that are new records
return host_or_hostgroup.content_facet.lifecycle_environment
end
selected_host_group = options.fetch(:selected_host_group, nil)
return selected_host_group.lifecycle_environment if selected_host_group.present?
end

def fetch_content_view(host_or_hostgroup, options = {})
return host_or_hostgroup.single_content_view if host_or_hostgroup.try(:single_content_view)
return host_or_hostgroup.content_view if host_or_hostgroup.try(:content_view)
if host_or_hostgroup.is_a?(::Hostgroup) && host_or_hostgroup.content_facet.present?
# to handle cloned hostgroups that are new records
return host_or_hostgroup.content_facet.content_view
end
selected_host_group = options.fetch(:selected_host_group, nil)
return selected_host_group.content_view if selected_host_group.present?
end

def fetch_content_source(host, options = {})
return host.content_source if host.try(:content_source_id)
def fetch_content_source(host_or_hostgroup, options = {})
return host_or_hostgroup.content_source if host_or_hostgroup.content_source_id&.present? && host_or_hostgroup.persisted?
if host_or_hostgroup.is_a?(::Hostgroup) && host_or_hostgroup.content_facet.present?
# to handle cloned hostgroups that are new records
return host_or_hostgroup.content_facet.content_source
end
selected_host_group = options.fetch(:selected_host_group, nil)
return selected_host_group.content_source if selected_host_group.present?
end
Expand Down
Loading