Skip to content

Commit

Permalink
Fixes #36869 - update hosts path with current_hosts_path
Browse files Browse the repository at this point in the history
  • Loading branch information
parthaa committed Nov 1, 2023
1 parent a941b8a commit fe49232
Show file tree
Hide file tree
Showing 29 changed files with 145 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def update_multiple_proxy(proxy_type, host_update_method)
"The %{proxy_type} puppet ca proxy could not be set for hosts: %{host_names}",
failed_hosts.count) % {:proxy_type => proxy_type, :host_names => failed_hosts.map { |h, err| "#{h} (#{err})" }.to_sentence}
end
redirect_back_or_to hosts_path
redirect_back_or_to current_hosts_path
end

def handle_proxy_messages(errors, proxy, proxy_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def update_multiple_taxonomies(type)
# simple validations
if params[type].nil? || (id = params[type][:id]).blank?
error "No #{type.to_s.classify} selected!"
redirect_to(hosts_path)
redirect_to(current_hosts_path)
return
end

Expand All @@ -46,11 +46,11 @@ def update_multiple_taxonomies(type)
@hosts.update_all("#{type}_id".to_sym => taxonomy.id)
else
error "Cannot update #{taxonomy.type} to #{taxonomy.name} because of mismatch in settings"
redirect_back_or_to hosts_path
redirect_back_or_to current_hosts_path
return
end
end
success "Updated hosts: Changed #{type.to_s.classify}"
redirect_back_or_to hosts_path
redirect_back_or_to current_hosts_path
end
end
32 changes: 14 additions & 18 deletions app/controllers/hosts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def update_multiple_owner
end

success _('Updated hosts: changed owner')
redirect_back_or_to hosts_path
redirect_back_or_to current_hosts_path
end

def select_multiple_power_state
Expand All @@ -480,7 +480,7 @@ def update_multiple_power_state
end

success _('The power state of the selected hosts will be set to %s') % _(action)
redirect_back_or_to hosts_path
redirect_back_or_to current_hosts_path
end

def multiple_destroy
Expand Down Expand Up @@ -516,7 +516,7 @@ def submit_rebuild_config
else
error message
end
redirect_to hosts_path
redirect_to current_hosts_path
end

def submit_multiple_build
Expand Down Expand Up @@ -546,7 +546,7 @@ def submit_multiple_build
else
error _("The following hosts failed the build operation: %s") % missed_hosts.map(&:name).to_sentence
end
redirect_to(hosts_path)
redirect_to(current_hosts_path)
end

def submit_multiple_destroy
Expand Down Expand Up @@ -584,7 +584,7 @@ def update_multiple_disassociate
host.disassociate!
end
success _('Updated hosts: Disassociated from VM')
redirect_back_or_to hosts_path
redirect_back_or_to current_hosts_path
end

def errors
Expand Down Expand Up @@ -684,12 +684,8 @@ def statuses
render :json => statuses
end

def hosts_path(*args)
if Setting[:new_hosts_page]
new_hosts_index_page_path(*args)
else
super
end
def current_hosts_path(*args)
helpers.current_hosts_path(*args)
end

private
Expand Down Expand Up @@ -784,12 +780,12 @@ def find_multiple
@hosts ||= resource_base.merge(Host.where(id: params[:host_ids]).or(Host.where(name: params[:host_names])))
if @hosts.empty?
error _('No hosts were found with that id, name or query filter')
redirect_to(hosts_path)
redirect_to(current_hosts_path)
return false
end
else
error _('No hosts selected')
redirect_to(hosts_path)
redirect_to(current_hosts_path)
return false
end

Expand All @@ -798,7 +794,7 @@ def find_multiple
message = _("Something went wrong while selecting hosts - %s") % error
error(message)
Foreman::Logging.exception(message, error)
redirect_to hosts_path
redirect_to current_hosts_path
false
end

Expand All @@ -812,7 +808,7 @@ def toggle_hostmode(mode = true)
else
error _("The following hosts were not %{action}: %{missed_hosts}") % { :action => action, :missed_hosts => missed_hosts.map(&:name).to_sentence }
end
redirect_to(hosts_path)
redirect_to(current_hosts_path)
end

# this is required for template generation (such as pxelinux) which is not done via a web request
Expand Down Expand Up @@ -895,7 +891,7 @@ def update_multiple_proxy(proxy_type, host_update_method)
"The %{proxy_type} puppet ca proxy could not be set for hosts: %{host_names}",
failed_hosts.count) % {:proxy_type => proxy_type, :host_names => failed_hosts.map { |h, err| "#{h} (#{err})" }.to_sentence}
end
redirect_back_or_to hosts_path
redirect_back_or_to current_hosts_path
end

def find_templates
Expand Down Expand Up @@ -939,14 +935,14 @@ def reported_origin_interval_settings
end

def redirection_url_on_host_deletion
default_redirection = { :success_redirect => hosts_path }
default_redirection = { :success_redirect => current_hosts_path }
return default_redirection unless session["redirect_to_url_#{controller_name}"]
path_hash = main_app.routes.recognize_path(session["redirect_to_url_#{controller_name}"])
return default_redirection if (path_hash.nil? || (path_hash && path_hash[:action] != 'index'))
{ :success_redirect => saved_redirect_url_or(send("#{controller_name}_url")) }
end

def current_host_details_path(host)
Setting['host_details_ui'] ? host_details_page_path(host) : host_path(host)
helpers.current_host_details_path(host)
end
end
10 changes: 5 additions & 5 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def update
if @user.update(user_params)
update_sub_hostgroups_owners

process_success((editing_self? && !current_user.allowed_to?({:controller => 'users', :action => 'index'})) ? { :success_redirect => hosts_path } : { :success_redirect => users_path })
process_success((editing_self? && !current_user.allowed_to?({:controller => 'users', :action => 'index'})) ? { :success_redirect => current_hosts_path } : { :success_redirect => users_path })
else
process_error
end
Expand Down Expand Up @@ -86,7 +86,7 @@ def impersonate
success _("You impersonated user %s, to cancel the session, click the impersonation icon in the top bar.") % user.name
Audit.create :auditable_type => 'User', :auditable_id => user.id, :user_id => User.current.id, :action => 'impersonate', :audited_changes => {}
logger.info "User #{User.current.name} impersonated #{user.name}"
redirect_to hosts_path
redirect_to current_hosts_path
else
info _("You are already impersonating, click the impersonation icon in the top bar before starting a new impersonation.")
redirect_to users_path
Expand Down Expand Up @@ -217,7 +217,7 @@ def login_user(user)
store_default_taxonomy(user, 'location') unless session.has_key?(:location_id)
TopbarSweeper.expire_cache
telemetry_increment_counter(:successful_ui_logins)
redirect_to (uri || hosts_path)
redirect_to (uri || current_hosts_path)
end

def parameter_filter_context
Expand All @@ -230,9 +230,9 @@ def verify_active_session
# Prevent a redirect loop in case the previous page was login page -
# e.g when csrf token expired but user already logged in from another tab
if request.headers["Referer"] == login_users_url
redirect_to hosts_path and return
redirect_to current_hosts_path and return
end
redirect_back_or_to hosts_path
redirect_back_or_to current_hosts_path
nil
end
end
Expand Down
24 changes: 12 additions & 12 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ def iana_timezone
Time.zone&.tzinfo&.name || 'UTC'
end

def current_hosts_path(*args)
if Setting[:new_hosts_page]
new_hosts_index_page_path(*args)
else
hosts_path(*args)
end
end

def current_host_details_path(host)
Setting['host_details_ui'] ? host_details_page_path(host) : host_path(host)
end

protected

def generate_date_id
Expand Down Expand Up @@ -418,16 +430,4 @@ def ui_settings
displayNewHostsPage: Setting[:new_hosts_page],
}
end

def current_host_details_path(host)
Setting['host_details_ui'] ? host_details_page_path(host) : host_path(host)
end

def hosts_path(*args)
if Setting[:new_hosts_page]
new_hosts_index_page_path(*args)
else
super
end
end
end
2 changes: 1 addition & 1 deletion app/helpers/audits_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def nested_host_audit_breadcrumbs
items: [
{
caption: _("Hosts"),
url: (hosts_path if authorized_for(hash_for_hosts_path)),
url: (current_hosts_path if authorized_for(hash_for_hosts_path)),
},
{
caption: @host.name,
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/dashboard_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_overview(report, options = {})

{
data: state_labels.map { |key, label| [label, report[key], report_color[key]] },
searchUrl: hosts_path(search: '~VAL~'),
searchUrl: current_hosts_path(search: '~VAL~'),
searchFilters: state_filters.each_with_object({}) do |(key, filter), filters|
filters[state_labels[key]] = search_filter_with_origin(filter, options[:origin], within_interval.include?(key), ignore_interval.include?(key))
end,
Expand All @@ -96,7 +96,7 @@ def searchable_links(name, search, counter)
content_tag :li do
content_tag(:span, raw(' '), :class => 'label', :style => "background-color:" + report_color[counter]) +
raw(' ') +
link_to(name, hosts_path(:search => search), :class => "dashboard-links") +
link_to(name, current_hosts_path(:search => search), :class => "dashboard-links") +
content_tag(:h4, @data.report[counter])
end
end
Expand Down
16 changes: 8 additions & 8 deletions app/helpers/host_description_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,21 @@ def base_host_overview_fields(host)
fields << { :field => [_("Build duration"), build_duration(host)], :priority => 90 }
fields << { :field => [_("Build errors"), link_to("Logs from OS installer", build_errors_host_path(:id => host.id))], :priority => 91 } if host.build_errors.present?
fields << { :field => [_("Token"), host.token || _("N/A")], :priority => 92 } if User.current.admin
fields << { :field => [_("Domain"), link_to(host.domain, hosts_path(:search => "domain = #{host.domain}"))], :priority => 100 } if host.domain.present?
fields << { :field => [_("Realm"), link_to(host.realm, hosts_path(:search => "realm = #{host.realm}"))], :priority => 200 } if host.realm.present?
fields << { :field => [_("Domain"), link_to(host.domain, current_hosts_path(:search => "domain = #{host.domain}"))], :priority => 100 } if host.domain.present?
fields << { :field => [_("Realm"), link_to(host.realm, current_hosts_path(:search => "realm = #{host.realm}"))], :priority => 200 } if host.realm.present?
fields << { :field => [_("IP Address"), host.ip], :priority => 300 } if host.ip.present?
fields << { :field => [_("IPv6 Address"), host.ip6], :priority => 400 } if host.ip6.present?
fields << { :field => [_("Comment"), host.comment], :priority => 500 } if host.comment.present?
fields << { :field => [_("MAC Address"), host.mac], :priority => 600 } if host.mac.present?
fields << { :field => [_("Architecture"), link_to(host.arch, hosts_path(:search => "architecture = #{host.arch}"))], :priority => 700 } if host.arch.present?
fields << { :field => [_("Operating System"), link_to(host.operatingsystem.to_label, hosts_path(:search => %{os_title = "#{host.operatingsystem.title}"}))], :priority => 800 } if host.operatingsystem.present?
fields << { :field => [_("Architecture"), link_to(host.arch, current_hosts_path(:search => "architecture = #{host.arch}"))], :priority => 700 } if host.arch.present?
fields << { :field => [_("Operating System"), link_to(host.operatingsystem.to_label, current_hosts_path(:search => %{os_title = "#{host.operatingsystem.title}"}))], :priority => 800 } if host.operatingsystem.present?
fields << { :field => [_("PXE Loader"), host.pxe_loader], :priority => 900 } if host.operatingsystem.present? && !host.image_build?
fields << { :field => [_("Host group"), link_to(host.hostgroup, hosts_path(:search => %{hostgroup_title = "#{host.hostgroup}"}))], :priority => 1000 } if host.hostgroup.present?
fields << { :field => [_("Host group"), link_to(host.hostgroup, current_hosts_path(:search => %{hostgroup_title = "#{host.hostgroup}"}))], :priority => 1000 } if host.hostgroup.present?
fields << { :field => [_("Boot time"), (boot_time = host&.reported_data&.boot_time) ? date_time_relative(boot_time) : _('Not reported')], :priority => 1100 }
fields << { :field => [_("Location"), link_to(host.location.title, hosts_path(:search => "location = \"#{host.location}\""))], :priority => 1200 } if host.location.present?
fields << { :field => [_("Organization"), link_to(host.organization.title, hosts_path(:search => "organization = \"#{host.organization}\""))], :priority => 1300 } if host.organization.present?
fields << { :field => [_("Location"), link_to(host.location.title, current_hosts_path(:search => "location = \"#{host.location}\""))], :priority => 1200 } if host.location.present?
fields << { :field => [_("Organization"), link_to(host.organization.title, current_hosts_path(:search => "organization = \"#{host.organization}\""))], :priority => 1300 } if host.organization.present?
if host.owner_type == "User"
fields << { :field => [_("Owner"), (link_to(host.owner, hosts_path(:search => %{user.login = "#{host.owner.login}"})) if host.owner)], :priority => 1400 }
fields << { :field => [_("Owner"), (link_to(host.owner, current_hosts_path(:search => %{user.login = "#{host.owner.login}"})) if host.owner)], :priority => 1400 }
else
fields << { :field => [_("Owner"), host.owner], :priority => 1400 }
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/provisioning_templates_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def building_hosts(template)

def building_hosts_path(template)
oses = template.operatingsystem_ids.map { |id| "os_id = #{id}" }.join(" or ")
hosts_path(:search => "build = true and ( #{oses} )")
current_hosts_path(:search => "build = true and ( #{oses} )")
end

def how_templates_are_determined
Expand Down
8 changes: 4 additions & 4 deletions app/presenters/host_status_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ def global_statuses
query = send("#{status_name}_total_query")
return if query.empty?

Rails.application.routes.url_helpers.hosts_path(search: query)
Rails.application.routes.url_helpers.current_hosts_path(search: query)
end

define_method :"#{status_name}_owned_path" do
query = send("#{status_name}_owned_query")
return if query.empty?

Rails.application.routes.url_helpers.hosts_path(search: query)
Rails.application.routes.url_helpers.current_hosts_path(search: query)
end
end

Expand All @@ -87,13 +87,13 @@ def all_statuses

def total_paths
total_queries.transform_values do |query|
Rails.application.routes.url_helpers.hosts_path(search: query)
Rails.application.routes.url_helpers.current_hosts_path(search: query)
end
end

def owned_paths
owned_queries.transform_values do |query|
Rails.application.routes.url_helpers.hosts_path(search: query)
Rails.application.routes.url_helpers.current_hosts_path(search: query)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/architectures/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<td class='ellipsis'><%= link_to_if_authorized(architecture.name,
hash_for_edit_architecture_path(:id => architecture).merge(:auth_object => architecture, :authorizer => authorizer)) %></td>
<td class="ellipsis"><%= architecture.operatingsystems.map(&:to_label).to_sentence %></td>
<td><%= link_to hosts_count[architecture], hosts_path(:search => "architecture = #{architecture}") %>
<td><%= link_to hosts_count[architecture], current_hosts_path(:search => "architecture = #{architecture}") %>
<td>
<%= action_buttons(display_delete_if_authorized hash_for_architecture_path(:id => architecture).merge(:auth_object => architecture, :authorizer => authorizer),
:data => { :confirm => _("Delete %s?") % architecture.name } ) %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/config_reports/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
items: [
{
caption: _("Hosts"),
url: (hosts_path if authorized_for(hash_for_hosts_path))
url: (current_hosts_path if authorized_for(hash_for_hosts_path))
},
{
caption: @host.name,
Expand Down
2 changes: 1 addition & 1 deletion app/views/domains/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<% @domains.each do |domain| %>
<tr>
<td class="ellipsis"><%= link_to_if_authorized (domain.fullname.empty? ? domain.name : domain.fullname), hash_for_edit_domain_path(:id => domain).merge(:auth_object => domain, :authorizer => authorizer) %></td>
<td><%= link_to hosts_count[domain], hosts_path(:search => "domain = #{domain}") %>
<td><%= link_to hosts_count[domain], current_hosts_path(:search => "domain = #{domain}") %>
<td class="col-md-1"><%= action_buttons(display_delete_if_authorized hash_for_domain_path(:id => domain).merge(:auth_object => domain, :authorizer => authorizer), :data => { :confirm => _("Delete %s?") % domain.name }) %></td>
</tr>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/hostgroups/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
<%= label_with_link(hostgroup, 150, authorizer) %>
</td>
<td>
<%= link_to hosts_count[hostgroup], hosts_path(:search => %Q[hostgroup_fullname = "#{hostgroup.title}"]) %>
<%= link_to hosts_count[hostgroup], current_hosts_path(:search => %Q[hostgroup_fullname = "#{hostgroup.title}"]) %>
</td>
<td>
<%= link_to hostgroup.children_hosts_count, hosts_path(:search => %Q[parent_hostgroup = "#{hostgroup.title}"]) %>
<%= link_to hostgroup.children_hosts_count, current_hosts_path(:search => %Q[parent_hostgroup = "#{hostgroup.title}"]) %>
</td>
<td>
<%= hostgroup_actions_dropdown(hostgroup) %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/hosts/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,6 @@

<%= hidden_field_tag 'bare_metal_capabilities', @host.bare_metal_capabilities, :disabled => true %>
<%= f.hidden_field :overwrite? %>
<%= submit_or_cancel f, @host.overwrite?, :cancel_path => resource_prev_url_with_search_filters || (@host.new_record? ? hosts_path : current_host_details_path(@host)) %>
<%= submit_or_cancel f, @host.overwrite?, :cancel_path => resource_prev_url_with_search_filters || (@host.new_record? ? current_hosts_path : current_host_details_path(@host)) %>
<% end %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/hosts/multiple_disassociate.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
'The list is excluding %{count} %{link_start}physical hosts%{link_end}.',
physical_count).html_safe % {
:count => physical_count,
:link_start => tag('a', {:href => hosts_path(:search => "name ^ (#{@physical_hosts.join(',')})")}, true),
:link_start => tag('a', {:href => current_hosts_path(:search => "name ^ (#{@physical_hosts.join(',')})")}, true),
:link_end => '</a>'.html_safe} %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/hosts/update_multiple_parameters.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
</li>
<% end %>
</ul>
<%= link_to _("Back to host list"), hosts_path %>
<%= link_to _("Back to host list"), current_hosts_path %>
2 changes: 1 addition & 1 deletion app/views/operatingsystems/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
%>
<tr>
<td class="ellipsis"><%= link_to_if_authorized(os_name(operatingsystem), hash_for_edit_operatingsystem_path(:id => operatingsystem).merge(:auth_object => operatingsystem, :authorizer => authorizer)) %></td>
<td><%= link_to hosts_count[operatingsystem], hosts_path(:search => "os_id = #{operatingsystem.id}") %></td>
<td><%= link_to hosts_count[operatingsystem], current_hosts_path(:search => "os_id = #{operatingsystem.id}") %></td>
<td>
<%= action_buttons(edit_btn, clone_btn, delete_btn) %>
</td>
Expand Down
Loading

0 comments on commit fe49232

Please sign in to comment.