From be9fb9924736386fdff60123025b4a41c1c042e5 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 15 Nov 2018 15:38:43 +0000 Subject: [PATCH] Redirect signed-in users to their service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some users are bookmarking the sign in page for quick access to their Notify service. If they’re already signed in when they used this bookmark they get redirected. However the redirect isn’t very smart, because it just takes them to their list of services. This isn’t great if they only have one service. This commit redirects them to the `show_accounts_or_dashboard` endpoint instead, which does the work to figure out which page is most useful to show someone when they sign in. Also changing this for `/register`, although it’s less likely that someone will have bookmarked this page. --- app/main/views/register.py | 2 +- app/main/views/sign_in.py | 2 +- tests/app/main/views/test_index.py | 2 +- tests/app/main/views/test_register.py | 18 +++++++----------- tests/app/main/views/test_sign_in.py | 11 +++++++---- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/app/main/views/register.py b/app/main/views/register.py index 247f916ec..4005e881c 100644 --- a/app/main/views/register.py +++ b/app/main/views/register.py @@ -16,7 +16,7 @@ from app.main.views.verify import activate_user @main.route('/register', methods=['GET', 'POST']) def register(): if current_user and current_user.is_authenticated: - return redirect(url_for('main.choose_account')) + return redirect(url_for('main.show_accounts_or_dashboard')) form = RegisterUserForm() if form.validate_on_submit(): diff --git a/app/main/views/sign_in.py b/app/main/views/sign_in.py index 8805b8512..82a5c14db 100644 --- a/app/main/views/sign_in.py +++ b/app/main/views/sign_in.py @@ -18,7 +18,7 @@ from app.main.forms import LoginForm @main.route('/sign-in', methods=(['GET', 'POST'])) def sign_in(): if current_user and current_user.is_authenticated: - return redirect(url_for('main.choose_account')) + return redirect(url_for('main.show_accounts_or_dashboard')) form = LoginForm() diff --git a/tests/app/main/views/test_index.py b/tests/app/main/views/test_index.py index e724451cb..2f179779a 100644 --- a/tests/app/main/views/test_index.py +++ b/tests/app/main/views/test_index.py @@ -37,7 +37,7 @@ def test_logged_in_user_redirects_to_choose_account( assert response.status_code == 302 response = logged_in_client.get(url_for('main.sign_in', follow_redirects=True)) - assert response.location == url_for('main.choose_account', _external=True) + assert response.location == url_for('main.show_accounts_or_dashboard', _external=True) def test_robots(client): diff --git a/tests/app/main/views/test_register.py b/tests/app/main/views/test_register.py index 5776afc98..39e59b5c4 100644 --- a/tests/app/main/views/test_register.py +++ b/tests/app/main/views/test_register.py @@ -18,18 +18,14 @@ def test_render_register_returns_template_with_form(client): assert 'Create an account' in response.get_data(as_text=True) -def test_logged_in_user_redirects_to_choose_account( - logged_in_client, - api_user_active, - mock_get_user_by_email, - mock_send_verify_code, - mock_login, +def test_logged_in_user_redirects_to_account( + client_request, ): - response = logged_in_client.get(url_for('main.register')) - assert response.status_code == 302 - - response = logged_in_client.get(url_for('main.sign_in', follow_redirects=True)) - assert response.location == url_for('main.choose_account', _external=True) + client_request.get( + 'main.register', + _expected_status=302, + _expected_redirect=url_for('main.show_accounts_or_dashboard', _external=True), + ) @pytest.mark.parametrize('phone_number_to_register_with', [ diff --git a/tests/app/main/views/test_sign_in.py b/tests/app/main/views/test_sign_in.py index bcfaf98a4..64208812d 100644 --- a/tests/app/main/views/test_sign_in.py +++ b/tests/app/main/views/test_sign_in.py @@ -73,11 +73,14 @@ def test_redirect_to_sign_in_if_logged_in_from_other_browser( assert response.location == url_for('main.sign_in', next='/accounts', _external=True) -def test_logged_in_user_redirects_to_choose_account( - logged_in_client +def test_logged_in_user_redirects_to_account( + client_request ): - response = logged_in_client.get(url_for('main.sign_in')) - assert response.location == url_for('main.choose_account', _external=True) + client_request.get( + 'main.sign_in', + _expected_status=302, + _expected_redirect=url_for('main.show_accounts_or_dashboard', _external=True), + ) @pytest.mark.parametrize('email_address, password', [