Tell template preview whether a letter can be sent internationally

If a service has permission to send international letters then the admin
app should tell template preview, so that template preview knows what
rules to apply when it’s validating the address of the letter.

We don’t need to wait for template preview to start looking at this
query string argument – it will just ignore it for now.
This commit is contained in:
Chris Hill-Scott
2020-04-30 12:11:37 +01:00
parent 0ef076f59e
commit 53724dacd1
4 changed files with 34 additions and 7 deletions

View File

@@ -115,7 +115,12 @@ def upload_letter(service_id):
file_location = get_transient_letter_file_location(service_id, upload_id)
try:
response = sanitise_letter(BytesIO(pdf_file_bytes))
response = sanitise_letter(
BytesIO(pdf_file_bytes),
allow_international_letters=current_service.has_permission(
'international_letters'
),
)
response.raise_for_status()
except RequestException as ex:
if ex.response is not None and ex.response.status_code == 400:

View File

@@ -94,9 +94,12 @@ def get_page_count_for_letter(template, values=None):
return page_count
def sanitise_letter(pdf_file):
def sanitise_letter(pdf_file, *, allow_international_letters):
return requests.post(
'{}/precompiled/sanitise'.format(current_app.config['TEMPLATE_PREVIEW_API_HOST']),
'{}/precompiled/sanitise?allow_international_letters={}'.format(
current_app.config['TEMPLATE_PREVIEW_API_HOST'],
'true' if allow_international_letters else 'false',
),
data=pdf_file,
headers={'Authorization': 'Token {}'.format(current_app.config['TEMPLATE_PREVIEW_API_KEY'])}
)