mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-03-12 14:22:37 -04:00
Move some methods from the API client to the model
They make more sense being on the model, and it doesn’t make any sense to duplicate them.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -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 [
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user