Merge pull request #2434 from alphagov/send-one-off-letter

Let people send one-off letters from the admin app
This commit is contained in:
Chris Hill-Scott
2018-11-02 09:33:04 +00:00
committed by GitHub
8 changed files with 245 additions and 63 deletions

View File

@@ -1,5 +1,6 @@
.page-footer {
position: relative;
margin-bottom: 30px;
&-back-link {
@@ -50,6 +51,12 @@
margin-top: $gutter;
}
&-right-aligned-link {
position: absolute;
right: 0;
top: 10px; // align baseline with buttons
}
.button,
.button-destructive {
margin-right: 10px;

View File

@@ -317,16 +317,13 @@ def send_test(service_id, template_id):
def get_notification_check_endpoint(service_id, template):
if template.template_type == 'letter':
return make_and_upload_csv_file(service_id, template)
else:
return redirect(url_for(
'main.check_notification',
service_id=service_id,
template_id=template.id,
# at check phase we should move to help stage 2 ("the template pulls in the data you provide")
help='2' if 'help' in request.args else None
))
return redirect(url_for(
'main.check_notification',
service_id=service_id,
template_id=template.id,
# at check phase we should move to help stage 2 ("the template pulls in the data you provide")
help='2' if 'help' in request.args else None
))
@main.route(
@@ -595,7 +592,6 @@ def _check_messages(service_id, template_id, upload_id, preview_row, letters_as_
trying_to_send_letters_in_trial_mode=all((
current_service.trial_mode,
template.template_type == 'letter',
not request.args.get('from_test'),
)),
required_recipient_columns=OrderedSet(recipients.recipient_column_headers) - optional_address_columns,
preview_row=preview_row,
@@ -669,6 +665,26 @@ def check_messages_preview(service_id, template_id, upload_id, filetype, row_ind
return TemplatePreview.from_utils_template(template, filetype, page=page)
@main.route(
"/services/<service_id>/<uuid:template_id>/check.<filetype>",
methods=['GET'],
)
@login_required
@user_has_permissions('send_messages')
def check_notification_preview(service_id, template_id, filetype):
if filetype == 'pdf':
page = None
elif filetype == 'png':
page = request.args.get('page', 1)
else:
abort(404)
template = _check_notification(
service_id, template_id,
)['template']
return TemplatePreview.from_utils_template(template, filetype, page=page)
@main.route("/services/<service_id>/start-job/<upload_id>", methods=['POST'])
@login_required
@user_has_permissions('send_messages', restrict_admin_usage=True)
@@ -762,8 +778,6 @@ def all_placeholders_in_session(placeholders):
def get_send_test_page_title(template_type, help_argument, entering_recipient, name=None):
if help_argument:
return 'Example text message'
if template_type == 'letter':
return 'Print a test letter'
if entering_recipient:
return 'Send {}'.format(name)
return 'Personalise this message'
@@ -807,7 +821,10 @@ def get_back_link(service_id, template, step_index):
@login_required
@user_has_permissions('send_messages', restrict_admin_usage=True)
def check_notification(service_id, template_id):
return _check_notification(service_id, template_id)
return render_template(
'views/notifications/check.html',
**_check_notification(service_id, template_id),
)
def _check_notification(service_id, template_id, exception=None):
@@ -823,25 +840,33 @@ def _check_notification(service_id, template_id, exception=None):
current_service,
show_recipient=True,
email_reply_to=email_reply_to,
sms_sender=sms_sender
sms_sender=sms_sender,
letter_preview_url=url_for(
'.check_notification_preview',
service_id=service_id,
template_id=template_id,
filetype='png',
),
page_count=get_page_count_for_letter(db_template),
)
back_link = get_back_link(service_id, template, len(fields_to_fill_in(template)))
if (
not session.get('recipient') or
not all_placeholders_in_session(template.placeholders)
(
not session.get('recipient')
and db_template['template_type'] != 'letter'
)
or not all_placeholders_in_session(template.placeholders)
):
return redirect(back_link)
raise RequestRedirect(back_link)
template.values = get_recipient_and_placeholders_from_session(template.template_type)
return render_template(
'views/notifications/check.html',
return dict(
template=template,
back_link=back_link,
help=get_help_argument(),
**(get_template_error_dict(exception) if exception else {})
**(get_template_error_dict(exception) if exception else {}),
)
@@ -880,7 +905,7 @@ def send_notification(service_id, template_id):
noti = notification_api_client.send_notification(
service_id,
template_id=template_id,
recipient=session['recipient'],
recipient=session['recipient'] or session['placeholders']['address line 1'],
personalisation=session['placeholders'],
sender_id=session['sender_id'] if 'sender_id' in session else None
)
@@ -889,7 +914,10 @@ def send_notification(service_id, template_id):
current_service.id,
exception.message
))
return _check_notification(service_id, template_id, exception)
return render_template(
'views/notifications/check.html',
**_check_notification(service_id, template_id, exception),
)
session.pop('placeholders')
session.pop('recipient')

View File

@@ -125,6 +125,7 @@ class HeaderNavigation(Navigation):
'check_messages',
'check_messages_preview',
'check_notification',
'check_notification_preview',
'choose_account',
'choose_service',
'choose_template',
@@ -395,6 +396,7 @@ class MainNavigation(Navigation):
'check_and_resend_text_code',
'check_and_resend_verification_code',
'check_messages_preview',
'check_notification_preview',
'choose_account',
'choose_service',
'confirm_edit_organisation_name',
@@ -567,6 +569,7 @@ class CaseworkNavigation(Navigation):
'check_messages',
'check_messages_preview',
'check_notification',
'check_notification_preview',
'choose_account',
'choose_service',
'choose_template_to_copy',
@@ -801,6 +804,7 @@ class OrgNavigation(Navigation):
'check_messages',
'check_messages_preview',
'check_notification',
'check_notification_preview',
'choose_account',
'choose_service',
'choose_template',

View File

@@ -0,0 +1,8 @@
<h1 class='banner-title' data-module="track-error" data-error-type="Trying to send letters in trial mode" data-error-label="{{ upload_id }}">
You cant send
{{ 'this letter' if count_of_recipients == 1 else 'these letters' }}
</h1>
<p>
In <a href="{{ url_for('.using_notify') }}#trial-mode">trial mode</a> you
can only preview how your letters will look
</p>

View File

@@ -109,14 +109,13 @@
{% elif trying_to_send_letters_in_trial_mode %}
<h1 class='banner-title' data-module="track-error" data-error-type="Trying to send letters in trial mode" data-error-label="{{ upload_id }}">
You cant send
{{ 'this letter' if count_of_recipients == 1 else 'these letters' }}
</h1>
<p>
In <a href="{{ url_for('.using_notify') }}#trial-mode">trial mode</a> you
can only preview how your letters will look
</p>
<div class="bottom-gutter">
{% with
count_of_recipients=count_of_recipients
%}
{% include "partials/check/trying-to-send-letters-in-trial-mode.html" %}
{% endwith %}
</div>
{% elif recipients.more_rows_than_can_send %}

View File

@@ -7,7 +7,18 @@
{% endblock %}
{% block maincolumn_content %}
{% if error == 'not-allowed-to-send-to' %}
{% if template.template_type == 'letter' and current_service.trial_mode %}
{% set error = 'trial-mode-letters' %}
<div class="bottom-gutter">
{% call banner_wrapper(type='dangerous') %}
{% with
count_of_recipients=1
%}
{% include "partials/check/trying-to-send-letters-in-trial-mode.html" %}
{% endwith %}
{% endcall %}
</div>
{% elif error == 'not-allowed-to-send-to' %}
<div class="bottom-gutter">
{% call banner_wrapper(type='dangerous') %}
{% with
@@ -50,13 +61,12 @@
)}}" class='page-footer'>
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
{% if not error %}
{% if template.template_type != 'letter' or not request.args.from_test %}
<button type="submit" class="button">Send 1 {{ message_count_label(1, template.template_type, suffix='') }}</button>
{% else %}
<a href="{{ url_for('main.check_messages_preview', service_id=current_service.id, template_id=template.id, upload_id=upload_id, filetype='pdf') }}" download class="button">Download as a printable PDF</a>
{% endif %}
{% endif %}
<a href="{{ back_link }}" class="page-footer-back-link">Back</a>
{% if template.template_type == 'letter' %}
<a href="{{ url_for('main.check_notification_preview', service_id=current_service.id, template_id=template.id, filetype='pdf') }}" download class="page-footer-right-aligned-link">Download as a printable PDF</a>
{% endif %}
</form>
</div>

View File

@@ -16,14 +16,9 @@
<div class="grid-row">
{% if template.template_type == 'letter' %}
{% if current_user.has_permissions('send_messages', restrict_admin_usage=True) %}
<div class="column-half">
<a href="{{ url_for(".send_messages", service_id=current_service.id, template_id=template.id) }}" class="pill-separate-item">
Upload a list of addresses
</a>
</div>
<div class="column-half">
<a href="{{ url_for(".set_sender", service_id=current_service.id, template_id=template.id) }}" class="pill-separate-item">
Print a test letter
Send
</a>
</div>
{% endif %}