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 #16530 - For active session - Redirect to :back or /hosts #3848

Conversation

swapab
Copy link
Member

@swapab swapab commented Sep 15, 2016

No description provided.

@theforeman-bot
Copy link
Member

Can an existing organization member please verify this patch?

2 similar comments
@theforeman-bot
Copy link
Member

Can an existing organization member please verify this patch?

@theforeman-bot
Copy link
Member

Can an existing organization member please verify this patch?

@theforeman-bot
Copy link
Member

There were the following issues with the commit message:

  • length of the first commit message line for cb6423c exceeds 65 characters
  • commit message for cb6423c is not wrapped at 72nd column

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use && instead of and.

@theforeman-bot
Copy link
Member

There were the following issues with the commit message:

  • length of the first commit message line for cb6423c exceeds 65 characters
  • commit message for cb6423c is not wrapped at 72nd column

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

Copy link
Contributor

@domcleal domcleal left a 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.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"logged in"

Copy link
Member Author

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
Copy link
Contributor

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.

Copy link
Member Author

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
Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Member Author

@swapab swapab Sep 18, 2016

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

Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Member Author

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? }
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated hash style.

@swapab swapab changed the title fixes #16530 - Logged-In user should be redirected to dashboard on re-visiting /users/login path fixes #16530 - Logged-In user should be redirected to dashboard Sep 16, 2016
@theforeman-bot
Copy link
Member

There were the following issues with the commit message:

  • length of the first commit message line for cb6423c exceeds 65 characters
  • commit message for cb6423c is not wrapped at 72nd column

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

@theforeman-bot
Copy link
Member

There were the following issues with the commit message:

  • length of the first commit message line for cb6423c exceeds 65 characters
  • commit message for cb6423c is not wrapped at 72nd column

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

@theforeman-bot
Copy link
Member

There were the following issues with the commit message:

  • length of the first commit message line for cb6423c exceeds 65 characters
  • commit message for cb6423c is not wrapped at 72nd column
  • length of the first commit message line for f9917a2 exceeds 65 characters
  • commit message for f9917a2 is not wrapped at 72nd column
  • f954828 must be in the format fixes #redmine_number - brief description
  • length of the first commit message line for f954828 exceeds 65 characters
  • commit message for f954828 is not wrapped at 72nd column

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

@theforeman-bot
Copy link
Member

There were the following issues with the commit message:

  • length of the first commit message line for cb6423c exceeds 65 characters
  • commit message for cb6423c is not wrapped at 72nd column
  • length of the first commit message line for f9917a2 exceeds 65 characters
  • commit message for f9917a2 is not wrapped at 72nd column
  • f954828 must be in the format fixes #redmine_number - brief description
  • length of the first commit message line for f954828 exceeds 65 characters
  • commit message for f954828 is not wrapped at 72nd column
  • 289f756 must be in the format fixes #redmine_number - brief description

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

@swapab
Copy link
Member Author

swapab commented Sep 18, 2016

@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.

@swapab swapab changed the title fixes #16530 - Logged-In user should be redirected to dashboard Fixes #16530 - For active session - Redirect to :back or /hosts Sep 18, 2016
context "when user is logged in" do
setup do
@previous_url = "/bookmarks"
get :login, set_session_user
Copy link
Contributor

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.

Copy link
Member Author

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
Copy link
Contributor

@domcleal domcleal Sep 19, 2016

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).

Copy link
Member Author

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
Copy link
Contributor

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.

Copy link
Member Author

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!

@domcleal
Copy link
Contributor

[test foreman]

Fixes #16530 - For active session - Redirect to :back or /hosts
@swapab
Copy link
Member Author

swapab commented Sep 19, 2016

@domcleal http://ci.theforeman.org/job/test_develop_pr_core/10484/#showFailuresLink
640 failures ? Are these usual ?
I am sure it is getting addressed somewhere. I would be happy to fix them.

@domcleal
Copy link
Contributor

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.

@domcleal
Copy link
Contributor

ok to test

@domcleal
Copy link
Contributor

Merged as be36ce9, thanks @swapnilabnave.

@domcleal domcleal closed this Sep 22, 2016
@swapab swapab deleted the 16530-if_active_session_then_no_login_page branch December 14, 2016 14:43
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants