From 88e36d6841c2dc7fa629352e9bd4852527100b82 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 7 Jun 2019 09:14:14 +0100 Subject: [PATCH] Move some methods from the API client to the model MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit They make more sense being on the model, and it doesn’t make any sense to duplicate them. --- app/main/views/service_settings.py | 2 +- app/main/views/templates.py | 2 +- app/models/user.py | 6 ++++++ app/notify_client/user_api_client.py | 13 ------------- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index 0d273c76d..874488587 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -222,7 +222,7 @@ def submit_request_to_go_live(service_id): volume_sms_formatted=format_if_number(current_service.volume_sms), volume_letter_formatted=format_if_number(current_service.volume_letter), research_consent='Yes' if current_service.consent_to_research else 'No', - existing_live='Yes' if user_api_client.user_has_live_services(current_user) else 'No', + existing_live='Yes' if current_user.live_services else 'No', email_address=current_user.email_address, ), ticket_type=zendesk_client.TYPE_QUESTION, diff --git a/app/main/views/templates.py b/app/main/views/templates.py index 5af350c24..e9a751190 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -402,7 +402,7 @@ def copy_template(service_id, template_id): form=form, template=template, heading_action='Add', - services=user_api_client.get_service_ids_for_user(current_user), + services=current_user.all_service_ids, ) diff --git a/app/models/user.py b/app/models/user.py index 2175d868e..8421c3878 100644 --- a/app/models/user.py +++ b/app/models/user.py @@ -241,6 +241,12 @@ class User(JSONModel, UserMixin): def all_services(self): return user_api_client.get_services_for_user(self.id) + @property + def all_service_ids(self): + return { + service['id'] for service in self.all_services + } + @property def trial_mode_services(self): return [ diff --git a/app/notify_client/user_api_client.py b/app/notify_client/user_api_client.py index 091d8f1d5..7d13935de 100644 --- a/app/notify_client/user_api_client.py +++ b/app/notify_client/user_api_client.py @@ -195,18 +195,5 @@ class UserApiClient(NotifyAdminAPIClient): ), []) return sorted(all_services, key=lambda service: service['name']) - def user_has_live_services(self, user): - return any( - not 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) - } - - def user_belongs_to_service(self, user, service_id): - return str(service_id) in self.get_service_ids_for_user(user) - user_api_client = UserApiClient()