From 688bdd1d7a9601a1eb2006472472ebda5a694830 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 12 Dec 2018 12:22:38 +0000 Subject: [PATCH 1/2] Note existing live services in go live ticket MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s useful for analysing our growth to know if someone who’s requesting to go live is already a live user of Notify. --- app/main/views/service_settings.py | 2 ++ app/notify_client/user_api_client.py | 5 +++++ tests/app/main/views/test_service_settings.py | 2 ++ 3 files changed, 9 insertions(+) diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index f7ef47802..79dc429cf 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -163,6 +163,7 @@ def submit_request_to_go_live(service_id): '\nText messages in next year: {volume_sms}' '\nLetters in next year: {volume_letter}' '\nConsent to research: {research_consent}' + '\nOther live services: {existing_live}' '\n' '\n---' '\n' @@ -189,6 +190,7 @@ def submit_request_to_go_live(service_id): volume_letter=form.volume_letter.data, volume_letter_normalised=form.volume_letter.data.replace(',', ''), research_consent=form.research_consent.data.title(), + existing_live='Yes' if user_api_client.user_has_live_services(current_user) else 'No', service_id=current_service.id, organisation=AgreementInfo.from_current_user().owner, user_name=current_user.name, diff --git a/app/notify_client/user_api_client.py b/app/notify_client/user_api_client.py index 78a694c88..6b53378ac 100644 --- a/app/notify_client/user_api_client.py +++ b/app/notify_client/user_api_client.py @@ -219,6 +219,11 @@ class UserApiClient(NotifyAdminAPIClient): ), []) return sorted(all_services, key=lambda service: service['name']) + def user_has_live_services(self, user): + return not all( + service['restricted'] for service in self.get_services_for_user(user) + ) + def get_service_ids_for_user(self, user): return { service['id'] for service in self.get_services_for_user(user) diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index 0f1b2a6e0..aa0750233 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -806,6 +806,7 @@ def test_should_redirect_after_request_to_go_live( single_reply_to_email_address, single_letter_contact_block, mock_get_service_organisation, + mock_get_organisations_and_services_for_user, single_sms_sender, mock_get_service_settings_page_common, mock_get_service_templates, @@ -849,6 +850,7 @@ def test_should_redirect_after_request_to_go_live( 'Text messages in next year: 222,222\n' 'Letters in next year: 333,333\n' 'Consent to research: Yes\n' + 'Other live services: No\n' '\n' '---\n' '{}, None, service one, Test User, test@user.gov.uk, -, 21/12/2012, 222222, 111111, 333333' From f44ff0bfc94c8d8b2911e8c8a40df86ab3a1593a Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 13 Dec 2018 10:37:44 +0000 Subject: [PATCH 2/2] Refactor live services check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes the check to say ‘does the user have any live services’ rather than ‘are all their services in trial mode’. The former is closer to meaning the thing we care about. Also has the opportunity to short-circuit without having to go through the full list. --- app/notify_client/user_api_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/notify_client/user_api_client.py b/app/notify_client/user_api_client.py index 6b53378ac..dfc3af797 100644 --- a/app/notify_client/user_api_client.py +++ b/app/notify_client/user_api_client.py @@ -220,8 +220,8 @@ class UserApiClient(NotifyAdminAPIClient): return sorted(all_services, key=lambda service: service['name']) def user_has_live_services(self, user): - return not all( - service['restricted'] for service in self.get_services_for_user(user) + return any( + not service['restricted'] for service in self.get_services_for_user(user) ) def get_service_ids_for_user(self, user):