diff --git a/app/__init__.py b/app/__init__.py index fbd736688..726e2a38b 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -27,7 +27,7 @@ from flask_wtf import CsrfProtect from functools import partial from notifications_python_client.errors import HTTPError -from notifications_utils import logging, request_id +from notifications_utils import logging, request_id, formatters from notifications_utils.clients.statsd.statsd_client import StatsdClient from notifications_utils.recipients import validate_phone_number, InvalidPhoneError from pygments import highlight @@ -134,6 +134,7 @@ def create_app(): application.add_template_filter(format_notification_status_as_field_status) application.add_template_filter(format_notification_status_as_url) application.add_template_filter(formatted_list) + application.add_template_filter(nl2br) application.after_request(useful_headers_after_request) application.after_request(save_service_after_request) @@ -375,6 +376,10 @@ def formatted_list( ).format(**locals()) +def nl2br(value): + return formatters.nl2br(value) if value else '' + + @login_manager.user_loader def load_user(user_id): return user_api_client.get_user(user_id) diff --git a/app/main/forms.py b/app/main/forms.py index 6e469be2b..9ae203e1f 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -486,10 +486,23 @@ class ServiceSmsSender(Form): ) def validate_sms_sender(form, field): - if field.data and not re.match('^[a-zA-Z0-9\s]+$', field.data): + if field.data and not re.match(r'^[a-zA-Z0-9\s]+$', field.data): raise ValidationError('Use letters and numbers only') +class ServiceLetterContactBlock(Form): + letter_contact_block = TextAreaField( + 'How should users contact you?' + ) + + def validate_letter_contact_block(form, field): + line_count = field.data.strip().count('\n') + if line_count >= 10: + raise ValidationError( + 'Contains {} lines, maximum is 10'.format(line_count + 1) + ) + + class ServiceBrandingOrg(Form): def __init__(self, organisations=[], *args, **kwargs): diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index 098bef06d..5c8f83ae3 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -25,6 +25,7 @@ from app.main.forms import ( RequestToGoLiveForm, ServiceReplyToEmailFrom, ServiceSmsSender, + ServiceLetterContactBlock, ServiceBrandingOrg ) from app import user_api_client, current_service, organisations_client @@ -236,6 +237,7 @@ def service_set_reply_to_email(service_id): reply_to_email_address=form.email_address.data ) return redirect(url_for('.service_settings', service_id=service_id)) + return render_template( 'views/service-settings/set-reply-to-email.html', form=form) @@ -259,6 +261,27 @@ def service_set_sms_sender(service_id): form=form) +@main.route("/services//service-settings/set-letter-contact-block", methods=['GET', 'POST']) +@login_required +@user_has_permissions('manage_settings', admin_override=True) +def service_set_letter_contact_block(service_id): + + if not current_service['can_send_letters']: + abort(403) + + form = ServiceLetterContactBlock(letter_contact_block=current_service['letter_contact_block']) + if form.validate_on_submit(): + service_api_client.update_service( + current_service['id'], + letter_contact_block=form.letter_contact_block.data.replace('\r', '') or None + ) + return redirect(url_for('.service_settings', service_id=service_id)) + return render_template( + 'views/service-settings/set-letter-contact-block.html', + form=form + ) + + @main.route("/services//service-settings/set-branding-and-org", methods=['GET', 'POST']) @login_required @user_has_permissions(admin_override=True) diff --git a/app/main/views/templates.py b/app/main/views/templates.py index a261401ab..b0f5a4a76 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -84,6 +84,7 @@ def view_letter_template_as_pdf(service_id, template_id): return render_pdf(HTML(string=str( LetterPreviewTemplate( service_api_client.get_service_template(service_id, template_id)['data'], + contact_block=current_service['letter_contact_block'], ) ))) @@ -144,6 +145,7 @@ def view_template_version_as_pdf(service_id, template_id, version): return render_pdf(HTML(string=str( LetterPreviewTemplate( service_api_client.get_service_template(service_id, template_id, version=version)['data'], + contact_block=current_service['letter_contact_block'], ) ))) diff --git a/app/notify_client/service_api_client.py b/app/notify_client/service_api_client.py index 8ab6049ae..5f93f7ca0 100644 --- a/app/notify_client/service_api_client.py +++ b/app/notify_client/service_api_client.py @@ -90,7 +90,8 @@ class ServiceAPIClient(NotifyAdminAPIClient): 'sms_sender', 'created_by', 'branding', - 'organisation' + 'organisation', + 'letter_contact_block' } if disallowed_attributes: raise TypeError('Not allowed to update service attributes: {}'.format( diff --git a/app/templates/components/textbox.html b/app/templates/components/textbox.html index 450059b59..2c66c923e 100644 --- a/app/templates/components/textbox.html +++ b/app/templates/components/textbox.html @@ -30,7 +30,9 @@ {% endif %} {{ field(**{ - 'class': 'form-control form-control-{} textbox-highlight-textbox'.format(width) if highlight_tags else 'form-control form-control-{} {}'.format(width, 'textbox-right-aligned' if suffix else ''), + 'class': + 'form-control form-control-{} textbox-highlight-textbox'.format(width) if highlight_tags else + 'form-control form-control-{} {}'.format(width, 'textbox-right-aligned' if suffix else ''), 'data-module': 'highlight-tags' if highlight_tags else '', 'rows': rows|string }) }} diff --git a/app/templates/partials/templates/guidance-contact-block.html b/app/templates/partials/templates/guidance-contact-block.html new file mode 100644 index 000000000..dda2aa91f --- /dev/null +++ b/app/templates/partials/templates/guidance-contact-block.html @@ -0,0 +1,8 @@ +

Contact details

+

+ Add contact details for your service in + settings. +

+

+ The text will appear in the top right of all letters your service sends. +

diff --git a/app/templates/views/edit-letter-template.html b/app/templates/views/edit-letter-template.html index f981b7008..28217c529 100644 --- a/app/templates/views/edit-letter-template.html +++ b/app/templates/views/edit-letter-template.html @@ -26,9 +26,10 @@ delete_link_text='Delete this template' ) }} -