From 1b395c04f37f508d1592ee3bb974beb0618c1fce Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 7 Jun 2019 13:06:53 +0100 Subject: [PATCH] Go straight into org if no trial mode services MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit You might still belong to some services, but because they’re live they’re all in your organisation. --- app/main/views/choose_account.py | 2 +- .../accounts/test_show_accounts_or_dashboard.py | 16 ++++++++++++---- tests/conftest.py | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/main/views/choose_account.py b/app/main/views/choose_account.py index e396ce040..9bbaf06dc 100644 --- a/app/main/views/choose_account.py +++ b/app/main/views/choose_account.py @@ -41,7 +41,7 @@ def show_accounts_or_dashboard(): if len(current_user.service_ids) == 1 and not current_user.organisation_ids: return redirect(url_for('.service_dashboard', service_id=current_user.service_ids[0])) - if len(current_user.organisation_ids) == 1 and not current_user.service_ids: + if len(current_user.organisation_ids) == 1 and not current_user.trial_mode_services: return redirect(url_for('.organisation_dashboard', org_id=current_user.organisation_ids[0])) return redirect(url_for('.choose_account')) diff --git a/tests/app/main/views/accounts/test_show_accounts_or_dashboard.py b/tests/app/main/views/accounts/test_show_accounts_or_dashboard.py index e9fa0f3c5..d5c5a3edf 100644 --- a/tests/app/main/views/accounts/test_show_accounts_or_dashboard.py +++ b/tests/app/main/views/accounts/test_show_accounts_or_dashboard.py @@ -16,7 +16,12 @@ def user_with_orgs_and_services(num_orgs, num_services, platform_admin=False): @pytest.mark.parametrize('num_orgs,num_services,endpoint,endpoint_kwargs', [ (0, 0, '.choose_account', {}), (0, 2, '.choose_account', {}), - (1, 1, '.choose_account', {}), + + # assumption is that live service is part of user’s organisation + # – real users shouldn’t have orphaned live services, or access to + # services belonging to other organisations + (1, 1, '.organisation_dashboard', {'org_id': 'org1'}), + (2, 0, '.choose_account', {}), (0, 1, '.service_dashboard', {'service_id': 'service1'}), (1, 0, '.organisation_dashboard', {'org_id': 'org1'}), @@ -24,6 +29,7 @@ def user_with_orgs_and_services(num_orgs, num_services, platform_admin=False): def test_show_accounts_or_dashboard_redirects_to_choose_account_or_service_dashboard( client, mocker, + mock_get_non_empty_organisations_and_services_for_user, num_orgs, num_services, endpoint, @@ -72,6 +78,7 @@ def test_show_accounts_or_dashboard_redirects_if_org_in_session(client, mocker): def test_show_accounts_or_dashboard_doesnt_redirect_to_service_dashboard_if_user_not_part_of_service_in_session( client, mocker, + mock_get_non_empty_organisations_and_services_for_user, mock_get_service ): client.login(user_with_orgs_and_services(num_orgs=1, num_services=1), mocker=mocker) @@ -82,12 +89,13 @@ def test_show_accounts_or_dashboard_doesnt_redirect_to_service_dashboard_if_user response = client.get(url_for('.show_accounts_or_dashboard')) assert response.status_code == 302 - assert response.location == url_for('main.choose_account', _external=True) + assert response.location == url_for('main.organisation_dashboard', org_id='org1', _external=True) def test_show_accounts_or_dashboard_doesnt_redirect_to_org_dashboard_if_user_not_part_of_org_in_session( client, - mocker + mocker, + mock_get_non_empty_organisations_and_services_for_user, ): client.login(user_with_orgs_and_services(num_orgs=1, num_services=1), mocker=mocker) with client.session_transaction() as session: @@ -97,7 +105,7 @@ def test_show_accounts_or_dashboard_doesnt_redirect_to_org_dashboard_if_user_not response = client.get(url_for('.show_accounts_or_dashboard')) assert response.status_code == 302 - assert response.location == url_for('main.choose_account', _external=True) + assert response.location == url_for('main.organisation_dashboard', org_id='org1', _external=True) def test_show_accounts_or_dashboard_redirects_if_not_logged_in( diff --git a/tests/conftest.py b/tests/conftest.py index d7b108a2d..aa65d3cf4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3355,6 +3355,7 @@ def mock_get_non_empty_organisations_and_services_for_user(mocker, organisation_ return [{ 'name': '{} {}'.format(name, i), 'id': SERVICE_TWO_ID, + 'restricted': False, } for i in range(1, 3)] def _get_orgs_and_services(user_id):