diff --git a/app/main/views/choose_account.py b/app/main/views/choose_account.py index b14dca2e4..e61ca6ee1 100644 --- a/app/main/views/choose_account.py +++ b/app/main/views/choose_account.py @@ -18,11 +18,8 @@ def services_or_dashboard(): @main.route("/accounts") @login_required def choose_account(): - orgs_and_services = current_user.orgs_and_services - return render_template( 'views/choose-account.html', - services_without_organisations=orgs_and_services['services_without_organisations'], can_add_service=current_user.is_gov_user, ) diff --git a/app/models/user.py b/app/models/user.py index 42b0df90c..ace1b2e18 100644 --- a/app/models/user.py +++ b/app/models/user.py @@ -268,6 +268,13 @@ class User(JSONModel, UserMixin): if not service['restricted'] ] + @property + def live_services_not_belonging_to_users_organisations(self): + return [ + service for service in self.orgs_and_services['services_without_organisations'] + if not service['restricted'] + ] + @property def organisations(self): return [ diff --git a/app/templates/views/choose-account.html b/app/templates/views/choose-account.html index 42d2ff031..fb9da0802 100644 --- a/app/templates/views/choose-account.html +++ b/app/templates/views/choose-account.html @@ -15,28 +15,26 @@
  • All organisations
  • -
    +
    {% endif %} - {% for org in current_user.organisations %} -
  • - {{ org.name }} -

    - {{ org.live_services|length }} - live service{% if org.live_services|length != 1 %}s{% endif %} -

    -
  • -
    - {% endfor %} - {% if services_without_organisations %} - {% for item in services_without_organisations %} + {% if current_user.organisations %} + {% for org in current_user.organisations %} +
  • + {{ org.name }} +

    + {{ org.live_services|length }} + live service{% if org.live_services|length != 1 %}s{% endif %} +

    +
  • +
    + {% endfor %} + {% for item in current_user.live_services_not_belonging_to_users_organisations %}
  • {{ item.name }}
  • {% endfor %} -
    - {% endif %} - {% if not current_user.organisations %} - {% if current_user.trial_mode_services %} + {% else %} + {% if current_user.trial_mode_services and current_user.live_services %}

    Live services diff --git a/tests/app/main/views/accounts/test_choose_accounts.py b/tests/app/main/views/accounts/test_choose_accounts.py index ca2abbefe..d26dacf42 100644 --- a/tests/app/main/views/accounts/test_choose_accounts.py +++ b/tests/app/main/views/accounts/test_choose_accounts.py @@ -59,9 +59,8 @@ def test_choose_account_should_show_choose_accounts_page( page = resp.find('div', {'id': 'content'}).main assert normalize_spaces(page.h1.text) == 'Choose service' - outer_list_items = page.nav.ul.find_all('li', recursive=False) - - assert len(outer_list_items) == 6 + outer_list_items = page.select('nav ul')[0].select('li') + assert len(outer_list_items) == 5 # first org assert outer_list_items[0].a.text == 'Org 1' @@ -84,13 +83,19 @@ def test_choose_account_should_show_choose_accounts_page( '0 live services' ) - # orphaned services + # orphaned live services assert outer_list_items[3].a.text == 'service_1' assert outer_list_items[3].a['href'] == url_for('.service_dashboard', service_id='s1') assert outer_list_items[4].a.text == 'service_2' assert outer_list_items[4].a['href'] == url_for('.service_dashboard', service_id='s2') - assert outer_list_items[5].a.text == 'service_3' - assert outer_list_items[5].a['href'] == url_for('.service_dashboard', service_id='s3') + + # orphaned live services + trial_services_list_items = page.select('nav ul')[1].select('li') + assert len(trial_services_list_items) == 2 + assert trial_services_list_items[0].a.text == 'org_service_3' + assert trial_services_list_items[0].a['href'] == url_for('.service_dashboard', service_id='os3') + assert trial_services_list_items[1].a.text == 'service_3' + assert trial_services_list_items[1].a['href'] == url_for('.service_dashboard', service_id='s3') def test_choose_account_should_show_choose_accounts_page_if_no_services(