mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
redacting a template now 400s if no updated_by_id supplied
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user