mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 23:41:17 -05:00
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:
@@ -69,7 +69,9 @@ def validate_parent_folder(template_json):
|
||||
def create_template(service_id):
|
||||
fetched_service = dao_fetch_service_by_id(service_id=service_id)
|
||||
# permissions needs to be placed here otherwise marshmallow will interfere with versioning
|
||||
permissions = fetched_service.permissions
|
||||
permissions = [
|
||||
p.permission for p in fetched_service.permissions
|
||||
]
|
||||
template_json = validate(request.get_json(), post_create_template_schema)
|
||||
folder = validate_parent_folder(template_json=template_json)
|
||||
new_template = Template.from_json(template_json, folder)
|
||||
@@ -102,7 +104,12 @@ def create_template(service_id):
|
||||
def update_template(service_id, template_id):
|
||||
fetched_template = dao_get_template_by_id_and_service_id(template_id=template_id, service_id=service_id)
|
||||
|
||||
if not service_has_permission(fetched_template.template_type, fetched_template.service.permissions):
|
||||
if not service_has_permission(
|
||||
fetched_template.template_type,
|
||||
[
|
||||
p.permission for p in fetched_template.service.permissions
|
||||
]
|
||||
):
|
||||
message = "Updating {} templates is not allowed".format(
|
||||
get_public_notify_type_text(fetched_template.template_type))
|
||||
errors = {'template_type': [message]}
|
||||
|
||||
Reference in New Issue
Block a user