-
Notifications
You must be signed in to change notification settings - Fork 987
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 #16530 - For active session - Redirect to :back or /hosts #3848
Fixes #16530 - For active session - Redirect to :back or /hosts #3848
Conversation
Can an existing organization member please verify this patch? |
2 similar comments
Can an existing organization member please verify this patch? |
Can an existing organization member please verify this patch? |
There were the following issues with the commit message:
If you don't have a ticket number, please create an issue in Redmine, selecting the appropriate project. More guidelines are available in Coding Standards or on the Foreman wiki. This message was auto-generated by Foreman's prprocessor |
def verify_active_session | ||
if params[:status].blank? && session[:user].present? && User.exists?(session[:user]) | ||
warning _("You have already Logged-In.") | ||
redirect_to root_path and return |
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.
Use && instead of and.
There were the following issues with the commit message:
If you don't have a ticket number, please create an issue in Redmine, selecting the appropriate project. More guidelines are available in Coding Standards or on the Foreman wiki. This message was auto-generated by Foreman's prprocessor |
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.
Please address the comments from @theforeman-bot about the length and style of your commit messages, see the links provided for more details. Please also squash the commits to one.
|
||
def verify_active_session | ||
if params[:status].blank? && session[:user].present? && User.exists?(session[:user]) | ||
warning _("You have already Logged-In.") |
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.
"logged in"
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.
Changed.
def verify_active_session | ||
if params[:status].blank? && session[:user].present? && User.exists?(session[:user]) | ||
warning _("You have already Logged-In.") | ||
redirect_to root_path |
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 should be the previous URL preferably, else hosts_path
to match login behaviour, and to work for users without dashboard permissions.
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.
Yes, that makes sense.
Previous url OR hosts_path in case no HTTP_REFERER
@@ -322,6 +322,7 @@ class UsersControllerTest < ActionController::TestCase | |||
end | |||
|
|||
test "#login renders login page" do | |||
session.clear |
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.
Instead of undoing the setup method, it might be better to try and move tests relying on this into a context that redefines setup_user
to an empty method.
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.
Sure @domcleal I am sorry I didn't quite get you. Could you please give an example?
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.
Please disregard, I don't think it's worthwhile any more - there were more instances of it in the previous version of the PR.
assert_redirected_to root_path | ||
end | ||
|
||
test "for user :one -> #login redirects to root(dashboard)" do |
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.
What does this test that the block above doesn't?
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 thought to also test it with different user(:one) along with default(:admin). Just to make sure users with different role behaves the same.
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.
Sorry, I missed this point. It's worth leaving out unless there's a difference in the tested code for the two types of user, just to minimise the test time.
end | ||
|
||
context "no active session present" do | ||
test "#login renders login page" do |
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 looks identical to the "#login renders login page" test on line 324.
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.
line 324 tests the response of :login
In above case the test is on rendered template. Maybe I can extend 324 case itself. Wont't that violate 1 assert per test standard ?
test "#login renders login page" do
session.clear
get :login
assert_response :success
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.
Sorry, I missed this point. One assertion per test isn't something we try to implement, it's OK if it's asserting multiple things as the test environment/request is identical.
Consider adding messages or comments to the assertions if it's unclear why they're testing what they do, but generally it's clearer to have one test block testing different things about the same request rather than spreading it out.
(So if you'd like to add the assert_template :login
back to the existing test, that'd be fine.)
assert_template :login | ||
end | ||
|
||
test "logout a logged-in user and visit /users/login should render login page" do |
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 don't think this tests anything that you haven't tested already.
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 should make sense now, with the new change of redirecting to :back
.
@@ -7,6 +7,7 @@ class UsersController < ApplicationController | |||
skip_before_action :require_login, :authorize, :session_expiry, :update_activity_time, :set_taxonomy, :set_gettext_locale_db, :only => [:login, :logout, :extlogout] | |||
skip_before_action :authorize, :only => :extlogin | |||
after_action :update_activity_time, :only => :login | |||
before_action :verify_active_session, only: :login, unless: -> { request.post? } |
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'd suggest sticking with the same hash style as the previous line for readability.
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 hash style.
/users/login
path
There were the following issues with the commit message:
If you don't have a ticket number, please create an issue in Redmine, selecting the appropriate project. More guidelines are available in Coding Standards or on the Foreman wiki. This message was auto-generated by Foreman's prprocessor |
There were the following issues with the commit message:
If you don't have a ticket number, please create an issue in Redmine, selecting the appropriate project. More guidelines are available in Coding Standards or on the Foreman wiki. This message was auto-generated by Foreman's prprocessor |
There were the following issues with the commit message:
If you don't have a ticket number, please create an issue in Redmine, selecting the appropriate project. More guidelines are available in Coding Standards or on the Foreman wiki. This message was auto-generated by Foreman's prprocessor |
There were the following issues with the commit message:
If you don't have a ticket number, please create an issue in Redmine, selecting the appropriate project. More guidelines are available in Coding Standards or on the Foreman wiki. This message was auto-generated by Foreman's prprocessor |
289f756
to
84d63d3
Compare
@domcleal Thank you for reviewing my PR. I have made the requested changes. Could you please have a look ? I have also rebased the commits to make it look cleaner. |
context "when user is logged in" do | ||
setup do | ||
@previous_url = "/bookmarks" | ||
get :login, set_session_user |
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 think this can be removed, it doesn't appear to be testing anything. The main requests are in the body of the test.
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.
Test refactored.
end | ||
end | ||
|
||
context "when user has logged out" do |
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 think you can remove this block, it tests the same thing as "#login renders login page" (rendering with an empty session).
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.
Removed.
def verify_active_session | ||
if !request.post? && params[:status].blank? && User.exists?(session[:user].presence) | ||
warning _("You have already logged in") | ||
redirect_to back_or_hosts |
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.
There is already a redirect_back_or_to
helper in the application controller, you should be able to call redirect_back_or_to hosts_path
.
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.
Nice. I used the helper method.
Thanks!
[test foreman] |
Fixes #16530 - For active session - Redirect to :back or /hosts
84d63d3
to
de2624d
Compare
@domcleal http://ci.theforeman.org/job/test_develop_pr_core/10484/#showFailuresLink |
Thanks for the update. They will be fixed under ticket http://projects.theforeman.org/issues/16599, I don't know if anybody is working on it right now. I'll retest once the develop branch has stabilised again. |
ok to test |
Merged as be36ce9, thanks @swapnilabnave. |
No description provided.