From 1ca0dfacf7805daaed13196617b93cb15d63faa5 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 7 Jun 2019 09:07:11 +0100 Subject: [PATCH] List all trial mode services MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At the moment the service list doesn’t disambiguate between live and trial mode services. This makes it hard to tell which of the things are important and which aren’t. The first step towards making this page clearer is to list trial mode services separately. --- app/models/user.py | 18 ++++++++++++++++ app/templates/views/choose-account.html | 21 ++++++++++++++++--- .../views/accounts/test_choose_accounts.py | 14 ++++++------- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/app/models/user.py b/app/models/user.py index 6af8e5aef..2175d868e 100644 --- a/app/models/user.py +++ b/app/models/user.py @@ -237,6 +237,24 @@ class User(JSONModel, UserMixin): def email_domain(self): return self.email_address.split('@')[-1] + @cached_property + def all_services(self): + return user_api_client.get_services_for_user(self.id) + + @property + def trial_mode_services(self): + return [ + service for service in self.all_services + if service['restricted'] + ] + + @property + def live_services(self): + return [ + service for service in self.all_services + if not service['restricted'] + ] + @cached_property def default_organisation(self): return Organisation( diff --git a/app/templates/views/choose-account.html b/app/templates/views/choose-account.html index e277b289f..6686a4e65 100644 --- a/app/templates/views/choose-account.html +++ b/app/templates/views/choose-account.html @@ -15,7 +15,7 @@
  • All organisations
  • -
    +
    {% endif %} {% for org in organisations %}
  • @@ -30,7 +30,7 @@ {% endif %}
  • -
    +
    {% endfor %} {% if services_without_organisations %} {% for item in services_without_organisations %} @@ -38,9 +38,24 @@ {{ item.name }} {% endfor %} -
    +
    + {% endif %} + {% if current_user.trial_mode_services %} + {% if organisations or current_user.live_services %} + +

    + Trial mode services +

    + + {% if can_add_service %}
    Add a new service diff --git a/tests/app/main/views/accounts/test_choose_accounts.py b/tests/app/main/views/accounts/test_choose_accounts.py index d84b7cb2f..f7c7f4fc3 100644 --- a/tests/app/main/views/accounts/test_choose_accounts.py +++ b/tests/app/main/views/accounts/test_choose_accounts.py @@ -15,16 +15,16 @@ SAMPLE_DATA = { 'name': 'org_1', 'id': 'o1', 'services': [ - {'name': 'org_service_1', 'id': 'os1'}, - {'name': 'org_service_2', 'id': 'os2'}, - {'name': 'org_service_3', 'id': 'os3'}, + {'name': 'org_service_1', 'id': 'os1', 'restricted': False}, + {'name': 'org_service_2', 'id': 'os2', 'restricted': False}, + {'name': 'org_service_3', 'id': 'os3', 'restricted': True}, ] }, { 'name': 'org_2', 'id': 'o2', 'services': [ - {'name': 'org_service_4', 'id': 'os4'}, + {'name': 'org_service_4', 'id': 'os4', 'restricted': False}, ] }, { @@ -34,9 +34,9 @@ SAMPLE_DATA = { } ], 'services_without_organisations': [ - {'name': 'service_1', 'id': 's1'}, - {'name': 'service_2', 'id': 's2'}, - {'name': 'service_3', 'id': 's3'}, + {'name': 'service_1', 'id': 's1', 'restricted': False}, + {'name': 'service_2', 'id': 's2', 'restricted': False}, + {'name': 'service_3', 'id': 's3', 'restricted': True}, ] }