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

@@ -7,6 +7,8 @@ from app.models import (
MOBILE_TYPE, EMAIL_TYPE,
KEY_TYPE_TEST, KEY_TYPE_TEAM, KEY_TYPE_NORMAL)
from app.dao.services_dao import dao_fetch_service_by_id
def get_recipients_from_request(request_json, key, type):
return [(type, recipient) for recipient in request_json.get(key)]
@@ -33,6 +35,10 @@ def service_allowed_to_send_to(recipient, service, key_type, allow_whitelisted_r
if key_type == KEY_TYPE_NORMAL and not service.restricted:
return True
# Revert back to the ORM model here so we can get some things which
# arent in the serialised model
service = dao_fetch_service_by_id(service.id)
team_members = itertools.chain.from_iterable(
[user.mobile_number, user.email_address] for user in service.users
)