Serialise service, API keys and permissions

By serialising these straight away we can:
- not go back to the database later, potentially closing the connection
  sooner
- potentially cache the serialised data, meaning we don’t touch the
  database at all
This commit is contained in:
Chris Hill-Scott
2020-06-22 11:10:10 +01:00
parent d7b2cc6403
commit 320bca70f7
11 changed files with 113 additions and 24 deletions

View File

@@ -123,7 +123,6 @@ def persist_notification(
template_version=template_version,
to=recipient,
service_id=service.id,
service=service,
personalisation=personalisation,
notification_type=notification_type,
api_key_id=api_key_id,

View File

@@ -90,7 +90,7 @@ def service_can_send_to_recipient(send_to, key_type, service, allow_whitelisted_
def service_has_permission(notify_type, permissions):
return notify_type in [p.permission for p in permissions]
return notify_type in permissions
def check_service_has_permission(notify_type, permissions):
@@ -137,7 +137,7 @@ def check_if_service_can_send_to_number(service, number):
if (
# if number is international and not a crown dependency
international_phone_info.international and not international_phone_info.crown_dependency
) and INTERNATIONAL_SMS_TYPE not in [p.permission for p in service.permissions]:
) and INTERNATIONAL_SMS_TYPE not in service.permissions:
raise BadRequestError(message="Cannot send to international mobile numbers")
else:
return international_phone_info