redacting a template now 400s if no updated_by_id supplied

This commit is contained in:
Leo Hemsted
2017-06-28 17:03:12 +01:00
parent 8ad10261ec
commit 3f663daafe
2 changed files with 24 additions and 10 deletions

View File

@@ -59,12 +59,8 @@ def update_template(service_id, template_id):
data = request.get_json()
# if redacting, don't update anything else
if data.get('redact_personalisation') is True and 'updated_by_id' in data:
# we also don't need to check what was passed in redact_personalisation - its presence in the dict is enough.
# also, only
if not fetched_template.redact_personalisation:
dao_redact_template(fetched_template, data['updated_by_id'])
return 'null', 200
if data.get('redact_personalisation') is True:
return redact_template(fetched_template, data)
current_data = dict(template_schema.dump(fetched_template).data.items())
updated_template = dict(template_schema.dump(fetched_template).data.items())
@@ -143,3 +139,16 @@ def _template_has_not_changed(current_data, updated_template):
current_data[key] == updated_template[key]
for key in ('name', 'content', 'subject', 'archived', 'process_type')
)
def redact_template(template, data):
# we also don't need to check what was passed in redact_personalisation - its presence in the dict is enough.
if 'updated_by_id' not in data:
message = 'Field is required'
errors = {'updated_by_id': [message]}
raise InvalidRequest(errors, status_code=400)
# if it's already redacted, then just return 200 straight away.
if not template.redact_personalisation:
dao_redact_template(template, data['updated_by_id'])
return 'null', 200