mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 14:09:20 -04:00
Show the first line of the address from the to field.
Now persisting the address to the "to" field of the Notification, after the notification has been validated. If the letter is pending validation, then "Checking..." will appear as the identifier for the letter. If the letter has passed validation, then the first line of the address (now persisted in the "to" field) will be displayed, with the client reference underneath. If the letter has failed validation the "Provided as PDF" will show be displayed, which is now the initial value of the "to" field.
This commit is contained in:
@@ -513,7 +513,7 @@ def add_preview_of_content_to_notifications(notifications):
|
||||
)
|
||||
else:
|
||||
if notification['template']['is_precompiled_letter']:
|
||||
notification['template']['subject'] = 'Provided as PDF'
|
||||
notification['template']['subject'] = notification['client_reference']
|
||||
yield dict(
|
||||
preview_of_content=(
|
||||
WithSubjectTemplate(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import base64
|
||||
import json
|
||||
import urllib
|
||||
import uuid
|
||||
from io import BytesIO
|
||||
|
||||
@@ -168,6 +169,25 @@ def _get_error_from_upload_form(form_errors):
|
||||
return error
|
||||
|
||||
|
||||
def format_recipient(address):
|
||||
'''
|
||||
To format the recipient we need to:
|
||||
- decode, address is url encoded
|
||||
- remove new line characters
|
||||
- remove whitespace around the lines
|
||||
- join the address lines, separated by a comma
|
||||
'''
|
||||
if not address:
|
||||
return address
|
||||
address = urllib.parse.unquote(address)
|
||||
stripped_address_lines_no_trailing_commas = [
|
||||
line.lstrip().rstrip(' ,')
|
||||
for line in address.splitlines() if line
|
||||
]
|
||||
one_line_address = ', '.join(stripped_address_lines_no_trailing_commas)
|
||||
return one_line_address
|
||||
|
||||
|
||||
@main.route("/services/<uuid:service_id>/preview-letter/<uuid:file_id>")
|
||||
@user_has_permissions('send_messages')
|
||||
def uploaded_letter_preview(service_id, file_id):
|
||||
@@ -179,7 +199,7 @@ def uploaded_letter_preview(service_id, file_id):
|
||||
status = metadata.get('status')
|
||||
error_shortcode = metadata.get('message')
|
||||
invalid_pages = metadata.get('invalid_pages')
|
||||
recipient = metadata.get('recipient')
|
||||
recipient = format_recipient(metadata.get('recipient'))
|
||||
|
||||
if invalid_pages:
|
||||
invalid_pages = json.loads(invalid_pages)
|
||||
@@ -246,11 +266,12 @@ def send_uploaded_letter(service_id):
|
||||
postage = form.postage.data
|
||||
metadata = get_letter_metadata(service_id, file_id)
|
||||
filename = metadata.get('filename')
|
||||
recipient_address = metadata.get('recipient')
|
||||
|
||||
if metadata.get('status') != 'valid':
|
||||
abort(403)
|
||||
|
||||
notification_api_client.send_precompiled_letter(service_id, filename, file_id, postage)
|
||||
notification_api_client.send_precompiled_letter(service_id, filename, file_id, postage, recipient_address)
|
||||
|
||||
return redirect(url_for(
|
||||
'.view_notification',
|
||||
|
||||
@@ -59,11 +59,12 @@ class NotificationApiClient(NotifyAdminAPIClient):
|
||||
data = _attach_current_user(data)
|
||||
return self.post(url='/service/{}/send-notification'.format(service_id), data=data)
|
||||
|
||||
def send_precompiled_letter(self, service_id, filename, file_id, postage):
|
||||
def send_precompiled_letter(self, service_id, filename, file_id, postage, recipient_address):
|
||||
data = {
|
||||
'filename': filename,
|
||||
'file_id': file_id,
|
||||
'postage': postage,
|
||||
'recipient_address': recipient_address
|
||||
}
|
||||
data = _attach_current_user(data)
|
||||
return self.post(url='/service/{}/send-pdf-letter'.format(service_id), data=data)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import json
|
||||
import urllib
|
||||
|
||||
from boto3 import resource
|
||||
from flask import current_app
|
||||
from notifications_utils.s3 import s3upload as utils_s3upload
|
||||
from notifications_utils.sanitise_text import SanitiseASCII
|
||||
|
||||
|
||||
def get_transient_letter_file_location(service_id, upload_id):
|
||||
@@ -31,7 +31,7 @@ def upload_letter_to_s3(
|
||||
if invalid_pages:
|
||||
metadata['invalid_pages'] = json.dumps(invalid_pages)
|
||||
if recipient:
|
||||
metadata['recipient'] = format_recipient(recipient)
|
||||
metadata['recipient'] = urllib.parse.quote(recipient)
|
||||
|
||||
utils_s3upload(
|
||||
filedata=data,
|
||||
@@ -59,20 +59,3 @@ def get_letter_metadata(service_id, file_id):
|
||||
s3_object = s3.Object(current_app.config['TRANSIENT_UPLOADED_LETTERS'], file_location).get()
|
||||
|
||||
return s3_object['Metadata']
|
||||
|
||||
|
||||
def format_recipient(address):
|
||||
'''
|
||||
To format the recipient we need to:
|
||||
- remove new line characters
|
||||
- remove whitespace around the lines
|
||||
- join the address lines, separated by a comma
|
||||
- convert the string to ASCII (S3 metadata must be stored as ASCII)
|
||||
'''
|
||||
stripped_address_lines_no_trailing_commas = [
|
||||
line.lstrip().rstrip(' ,')
|
||||
for line in address.splitlines() if line
|
||||
]
|
||||
one_line_address = ', '.join(stripped_address_lines_no_trailing_commas)
|
||||
|
||||
return SanitiseASCII.encode(one_line_address)
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
) %}
|
||||
{% call row_heading() %}
|
||||
{% if item.status in ('pending-virus-check', 'virus-scan-failed') %}
|
||||
<span class="file-list-filename">{{ item.to }}</span>
|
||||
<span class="file-list-filename loading-indicator">Checking</span>
|
||||
{% else %}
|
||||
<a class="file-list-filename" href="{{ url_for('.view_notification', service_id=current_service.id, notification_id=item.id) }}">{{ item.to }}</a>
|
||||
<a class="file-list-filename" href="{{ url_for('.view_notification', service_id=current_service.id, notification_id=item.id) }}">{{ item.to.split('\n')[0] }}</a>
|
||||
{% endif %}
|
||||
<p class="file-list-hint">
|
||||
{{ item.preview_of_content }}
|
||||
|
||||
Reference in New Issue
Block a user