Refuse to process invalid files

Since the admin app won’t be checking the metadata when it starts a job
now it’s possible that someone could make a post request which attempts
to start a job for an invalid file. This commit adds a check to make
sure that can’t happen.

This is more of an extra safety thing, rather than something that the
admin app or a user will see.
This commit is contained in:
Chris Hill-Scott
2018-04-30 11:47:27 +01:00
parent a4857c08ab
commit 84024a9efc
2 changed files with 51 additions and 28 deletions

View File

@@ -127,11 +127,15 @@ def create_job(service_id):
except KeyError:
raise InvalidRequest({'id': ['Missing data for required field.']}, status_code=400)
data['template'] = data.pop('template_id')
template = dao_get_template_by_id(data['template'])
if template.template_type == LETTER_TYPE and service.restricted:
raise InvalidRequest("Create letter job is not allowed for service in trial mode ", 403)
if data.get('valid') != 'True':
raise InvalidRequest("File is not valid, can't create job", 400)
errors = unarchived_template_schema.validate({'archived': template.archived})
if errors: