-
Notifications
You must be signed in to change notification settings - Fork 991
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 #36869 - Redirect /hosts to /new/hosts in index #9879
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of this. With the host detail page we took an approach of making sure the links to it were correct, but still retained the old detail page as a fallback. This implementation means you effectively disable the whole old host page. If you go that route, why don't you make /hosts
return the new content?
app/controllers/hosts_controller.rb
Outdated
if Setting[:new_hosts_page] | ||
redirect_to(new_hosts_index_page_path) | ||
next | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do this, why can't it be at at the very beginning? So line 42.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to try your approach. @jeremylenz what do you think ?
Well, for what it's worth, I just tested this and it unbreaks host create. So 👍 in that regard. |
2c65e61
to
344051d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Host create works
also did some spot checks and links go to the correct place.
APJ (and @ekohl) 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was late on the other PR, but one thing I really didn't like about the new host detail page was the URL change.
In your current implementation you're treating the pages as if they're equal: you can go to either one or the other. Can't we somehow implement the page in the controller to either render the old or the new version? Either based on preference or cookie.
The thing I'm mostly worried about is this scenario:
- Have the setting set to prefer the new overview
- Go to the old overview
- Use a bulk action
- Expect to be redirect back to old overview
In reality this will redirect to the new overview.
Another case I fear about is plugins. They may redirect to the hosts overview as well.
app/controllers/hosts_controller.rb
Outdated
@@ -684,11 +684,11 @@ def statuses | |||
render :json => statuses | |||
end | |||
|
|||
def hosts_path(*args) | |||
def current_hosts_path(*args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't controllers include all helpers? So isn't this duplicating the current_hosts_path
from ApplicationHelper
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated it use helpers.current_hosts_path
instead
app/helpers/application_helper.rb
Outdated
@@ -423,11 +423,11 @@ def current_host_details_path(host) | |||
Setting['host_details_ui'] ? host_details_page_path(host) : host_path(host) | |||
end | |||
|
|||
def hosts_path(*args) | |||
def current_hosts_path(*args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: is current
the best naming? Perhaps preferred
is better, though it's also not great either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is consistent with current_host_details_path
which was already there. 🤷
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work?
You bring up an interesting idea here.
Actually I just realized most of the actions on host_controller do what you were suggesting. Something like Which then runs def redirect_back(fallback_location:, allow_other_host: true, **args)
referer = request.headers["Referer"]
redirect_to_referer = referer && (allow_other_host || _url_host_allowed?(referer))
redirect_to redirect_to_referer ? referer : fallback_location, **args
end This would mean that if the referer pointed to the old page they'd be redirected back to that and the new url would only be a fall back |
@ekohl any thoughts on ^ ? |
2b93a60
to
0fb71e5
Compare
That sounds like it would be less of a problem than I was afraid of, which is good. |
f086b71
to
3263b37
Compare
@jeremylenz can you run a quick test again on this and ack if it works |
2bb24b7
to
5ffd2d7
Compare
[test unit] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested host create again and spot checked a few links, still works well for me
[test unit] |
2 similar comments
[test unit] |
[test unit] |
Comments in #9879 (review) were addressed
Also removed logic in the hosts controller and application helper to rewrite the URL. Decided to go with the redirect on index approach instead since we want this redirect to happen only on get requests.
Test this
http://<satellite>/hosts
and notice that it should get redirected tohttp://<satellite>/new/hosts