From ba7d9cd4863738ade3f147bab21d69f68d6611b5 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Sun, 24 Apr 2016 09:46:44 +0100 Subject: [PATCH 1/2] If not logged in, go home when clicking GOV.UK MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s a bit of a weird experience to be taken to the sign in screen when you click GOV.UK in the header. It’s doubly weird if you take the tour before creating an account, and at the end of the tour you get prompted to sign in. This commit adds some extra logic to take you to the homepage instead, which I think is more what you’d expect. --- app/main/views/choose_service.py | 5 ++++- tests/app/main/views/test_choose_services.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/main/views/choose_service.py b/app/main/views/choose_service.py index 657e6ab22..8a96f3524 100644 --- a/app/main/views/choose_service.py +++ b/app/main/views/choose_service.py @@ -16,8 +16,11 @@ def choose_service(): @main.route("/services-or-dashboard") -@login_required def show_all_services_or_dashboard(): + + if not current_user.is_authenticated(): + return redirect(url_for('.index')) + services = service_api_client.get_services({'user_id': current_user.id})['data'] if 1 == len(services): diff --git a/tests/app/main/views/test_choose_services.py b/tests/app/main/views/test_choose_services.py index ba8714fec..e1ecc14f1 100644 --- a/tests/app/main/views/test_choose_services.py +++ b/tests/app/main/views/test_choose_services.py @@ -59,7 +59,7 @@ def test_should_redirect_if_not_logged_in(app_): with app_.test_client() as client: response = client.get(url_for('main.show_all_services_or_dashboard')) assert response.status_code == 302 - assert url_for('main.sign_in', _external=True) in response.location + assert url_for('main.index', _external=True) in response.location def test_should_show_all_services_for_platform_admin_user(app_, From 41fa6c61eef36b913842cfd03ff850ae363eca06 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Sun, 24 Apr 2016 09:47:42 +0100 Subject: [PATCH 2/2] Add test for redirecting to service in session MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If you click GOV.UK and have: - multiple services - a service in your session …we take you to the dashboard for that service. This worked great, but wasn’t tested. This commit adds a test for it. --- tests/app/main/views/test_choose_services.py | 25 +++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/app/main/views/test_choose_services.py b/tests/app/main/views/test_choose_services.py index e1ecc14f1..f7b77b3dc 100644 --- a/tests/app/main/views/test_choose_services.py +++ b/tests/app/main/views/test_choose_services.py @@ -1,4 +1,4 @@ -from flask import url_for +from flask import url_for, session def test_should_show_choose_services_page(app_, @@ -54,6 +54,29 @@ def test_redirect_if_multiple_services( assert response.location == url_for('main.choose_service', _external=True) +def test_redirect_if_service_in_session( + app_, + mock_login, + mock_get_user, + api_user_active, + mock_get_services, + mock_get_service +): + with app_.test_request_context(): + with app_.test_client() as client: + client.login(api_user_active) + with client.session_transaction() as session: + session['service_id'] = '147ad62a-2951-4fa1-9ca0-093cd1a52c52' + response = client.get(url_for('main.show_all_services_or_dashboard')) + + assert response.status_code == 302 + assert response.location == url_for( + 'main.service_dashboard', + service_id='147ad62a-2951-4fa1-9ca0-093cd1a52c52', + _external=True + ) + + def test_should_redirect_if_not_logged_in(app_): with app_.test_request_context(): with app_.test_client() as client: