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() data = request.get_json()
# if redacting, don't update anything else # if redacting, don't update anything else
if data.get('redact_personalisation') is True and 'updated_by_id' in data: if data.get('redact_personalisation') is True:
# we also don't need to check what was passed in redact_personalisation - its presence in the dict is enough. return redact_template(fetched_template, data)
# also, only
if not fetched_template.redact_personalisation:
dao_redact_template(fetched_template, data['updated_by_id'])
return 'null', 200
current_data = dict(template_schema.dump(fetched_template).data.items()) current_data = dict(template_schema.dump(fetched_template).data.items())
updated_template = 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] current_data[key] == updated_template[key]
for key in ('name', 'content', 'subject', 'archived', 'process_type') 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

View File

@@ -617,15 +617,20 @@ def test_update_redact_template_does_nothing_if_already_redacted(admin_request,
assert sample_template.template_redacted.updated_at == dt assert sample_template.template_redacted.updated_at == dt
def test_update_redact_template_400s_if_no_updated_by(admin_request, sample_template):
def test_update_redact_template_does_nothing_if_no_updated_by(admin_request, sample_template):
original_updated_time = sample_template.template_redacted.updated_at original_updated_time = sample_template.template_redacted.updated_at
admin_request.post( resp = admin_request.post(
'template.update_template', 'template.update_template',
service_id=sample_template.service_id, service_id=sample_template.service_id,
template_id=sample_template.id, template_id=sample_template.id,
_data={'redact_personalisation': True} _data={'redact_personalisation': True},
_expected_status=400
) )
assert resp == {
'result': 'error',
'message': {'updated_by_id': ['Field is required']}
}
assert sample_template.redact_personalisation is False assert sample_template.redact_personalisation is False
assert sample_template.template_redacted.updated_at == original_updated_time assert sample_template.template_redacted.updated_at == original_updated_time