mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 10:53:28 -05:00
Merge branch 'main' into 1210-create-confirmation-status-page-the-last-page-in-the-preview-send-flow
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import itertools
|
||||
import time
|
||||
import uuid
|
||||
from string import ascii_uppercase
|
||||
@@ -6,6 +5,7 @@ from zipfile import BadZipFile
|
||||
|
||||
from flask import abort, flash, redirect, render_template, request, session, url_for
|
||||
from flask_login import current_user
|
||||
from markupsafe import Markup
|
||||
from notifications_python_client.errors import HTTPError
|
||||
from notifications_utils import SMS_CHAR_COUNT_LIMIT
|
||||
from notifications_utils.insensitive_dict import InsensitiveDict
|
||||
@@ -151,8 +151,11 @@ def send_messages(service_id, template_id):
|
||||
# just show the first error, as we don't expect the form to have more
|
||||
# than one, since it only has one field
|
||||
first_field_errors = list(form.errors.values())[0]
|
||||
flash(first_field_errors[0])
|
||||
|
||||
error_message = '<span class="usa-error-message">'
|
||||
error_message = f"{error_message}{first_field_errors[0]}"
|
||||
error_message = f"{error_message}</span>"
|
||||
error_message = Markup(error_message)
|
||||
flash(error_message)
|
||||
column_headings = get_spreadsheet_column_headings_from_template(template)
|
||||
|
||||
return render_template(
|
||||
@@ -504,23 +507,38 @@ def _check_messages(service_id, template_id, upload_id, preview_row):
|
||||
template = get_template(
|
||||
db_template,
|
||||
current_service,
|
||||
show_recipient=True,
|
||||
show_recipient=False,
|
||||
email_reply_to=email_reply_to,
|
||||
sms_sender=sms_sender,
|
||||
)
|
||||
simplifed_template = get_template(
|
||||
db_template,
|
||||
current_service,
|
||||
show_recipient=False,
|
||||
)
|
||||
|
||||
allow_list = []
|
||||
if current_service.trial_mode:
|
||||
# Adding the simulated numbers to allow list
|
||||
# so they can be sent in trial mode
|
||||
for user in Users(service_id):
|
||||
allow_list.extend([user.name, user.mobile_number, user.email_address])
|
||||
# Failed sms number
|
||||
allow_list.extend(
|
||||
["simulated user (fail)", "+14254147167", "simulated@simulated.gov"]
|
||||
)
|
||||
# Success sms number
|
||||
allow_list.extend(
|
||||
["simulated user (success)", "+14254147755", "simulatedtwo@simulated.gov"]
|
||||
)
|
||||
else:
|
||||
allow_list = None
|
||||
recipients = RecipientCSV(
|
||||
contents,
|
||||
template=template,
|
||||
template=template or simplifed_template,
|
||||
max_initial_rows_shown=50,
|
||||
max_errors_shown=50,
|
||||
guestlist=(
|
||||
itertools.chain.from_iterable(
|
||||
[user.name, user.mobile_number, user.email_address]
|
||||
for user in Users(service_id)
|
||||
)
|
||||
if current_service.trial_mode
|
||||
else None
|
||||
),
|
||||
guestlist=allow_list,
|
||||
remaining_messages=remaining_messages,
|
||||
allow_international_sms=current_service.has_permission("international_sms"),
|
||||
)
|
||||
@@ -530,11 +548,20 @@ def _check_messages(service_id, template_id, upload_id, preview_row):
|
||||
back_link = url_for(
|
||||
"main.send_one_off", service_id=service_id, template_id=template.id
|
||||
)
|
||||
back_link_from_preview = url_for(
|
||||
"main.send_one_off", service_id=service_id, template_id=template.id
|
||||
)
|
||||
choose_time_form = None
|
||||
else:
|
||||
back_link = url_for(
|
||||
"main.send_messages", service_id=service_id, template_id=template.id
|
||||
)
|
||||
back_link_from_preview = url_for(
|
||||
"main.check_messages",
|
||||
service_id=service_id,
|
||||
template_id=template.id,
|
||||
upload_id=upload_id,
|
||||
)
|
||||
choose_time_form = ChooseTimeForm()
|
||||
|
||||
if preview_row < 2:
|
||||
@@ -542,6 +569,9 @@ def _check_messages(service_id, template_id, upload_id, preview_row):
|
||||
|
||||
if preview_row < len(recipients) + 2:
|
||||
template.values = recipients[preview_row - 2].recipient_and_personalisation
|
||||
simplifed_template.values = recipients[
|
||||
preview_row - 2
|
||||
].recipient_and_personalisation
|
||||
elif preview_row > 2:
|
||||
abort(404)
|
||||
|
||||
@@ -562,11 +592,14 @@ def _check_messages(service_id, template_id, upload_id, preview_row):
|
||||
remaining_messages=remaining_messages,
|
||||
choose_time_form=choose_time_form,
|
||||
back_link=back_link,
|
||||
back_link_from_preview=back_link_from_preview,
|
||||
first_recipient_column=recipients.recipient_column_headers[0],
|
||||
preview_row=preview_row,
|
||||
sent_previously=job_api_client.has_sent_previously(
|
||||
service_id, template.id, db_template["version"], original_file_name
|
||||
),
|
||||
template_id=template_id,
|
||||
simplifed_template=simplifed_template,
|
||||
)
|
||||
|
||||
|
||||
@@ -614,13 +647,34 @@ def check_messages(service_id, template_id, upload_id, row_index=2):
|
||||
return render_template("views/check/ok.html", **data)
|
||||
|
||||
|
||||
@main.route(
|
||||
"/services/<uuid:service_id>/<uuid:template_id>/check/<uuid:upload_id>/preview",
|
||||
methods=["POST"],
|
||||
)
|
||||
@main.route(
|
||||
"/services/<uuid:service_id>/<uuid:template_id>/check/<uuid:upload_id>/preview/row-<int:row_index>",
|
||||
methods=["POST"],
|
||||
)
|
||||
@user_has_permissions("send_messages", restrict_admin_usage=True)
|
||||
def preview_job(service_id, template_id, upload_id, row_index=2):
|
||||
session["scheduled_for"] = request.form.get("scheduled_for", "")
|
||||
data = _check_messages(service_id, template_id, upload_id, row_index)
|
||||
|
||||
return render_template(
|
||||
"views/check/preview.html",
|
||||
scheduled_for=session["scheduled_for"],
|
||||
**data,
|
||||
)
|
||||
|
||||
|
||||
@main.route("/services/<uuid:service_id>/start-job/<uuid:upload_id>", methods=["POST"])
|
||||
@user_has_permissions("send_messages", restrict_admin_usage=True)
|
||||
def start_job(service_id, upload_id):
|
||||
scheduled_for = session.pop("scheduled_for", None)
|
||||
job_api_client.create_job(
|
||||
upload_id,
|
||||
service_id,
|
||||
scheduled_for=request.form.get("scheduled_for", ""),
|
||||
scheduled_for=scheduled_for,
|
||||
)
|
||||
|
||||
session.pop("sender_id", None)
|
||||
@@ -679,7 +733,20 @@ def get_send_test_page_title(template_type, entering_recipient, name=None):
|
||||
return "Personalize this message"
|
||||
|
||||
|
||||
def get_back_link(service_id, template, step_index, placeholders=None):
|
||||
def get_back_link(
|
||||
service_id,
|
||||
template,
|
||||
step_index,
|
||||
placeholders=None,
|
||||
preview=False,
|
||||
):
|
||||
if preview:
|
||||
return url_for(
|
||||
"main.check_notification",
|
||||
service_id=service_id,
|
||||
template_id=template.id,
|
||||
)
|
||||
|
||||
if step_index == 0:
|
||||
if should_skip_template_page(template._template):
|
||||
return url_for(
|
||||
@@ -779,11 +846,18 @@ def _check_notification(service_id, template_id, exception=None):
|
||||
email_reply_to=email_reply_to,
|
||||
sms_sender=sms_sender,
|
||||
)
|
||||
|
||||
simplifed_template = get_template(
|
||||
db_template,
|
||||
current_service,
|
||||
)
|
||||
placeholders = fields_to_fill_in(template)
|
||||
|
||||
back_link = get_back_link(service_id, template, len(placeholders), placeholders)
|
||||
|
||||
back_link_from_preview = get_back_link(
|
||||
service_id, template, len(placeholders), placeholders, preview=True
|
||||
)
|
||||
|
||||
choose_time_form = ChooseTimeForm()
|
||||
|
||||
if (not session.get("recipient")) or not all_placeholders_in_session(
|
||||
@@ -797,8 +871,10 @@ def _check_notification(service_id, template_id, exception=None):
|
||||
return dict(
|
||||
template=template,
|
||||
back_link=back_link,
|
||||
back_link_from_preview=back_link_from_preview,
|
||||
choose_time_form=choose_time_form,
|
||||
**(get_template_error_dict(exception) if exception else {}),
|
||||
simplifed_template=simplifed_template,
|
||||
)
|
||||
|
||||
|
||||
@@ -828,12 +904,39 @@ def get_template_error_dict(exception):
|
||||
}
|
||||
|
||||
|
||||
@main.route(
|
||||
"/services/<uuid:service_id>/template/<uuid:template_id>/notification/check/preview",
|
||||
methods=["POST"],
|
||||
)
|
||||
@user_has_permissions("send_messages", restrict_admin_usage=True)
|
||||
def preview_notification(service_id, template_id):
|
||||
recipient = get_recipient()
|
||||
if not recipient:
|
||||
return redirect(
|
||||
url_for(
|
||||
".send_one_off",
|
||||
service_id=service_id,
|
||||
template_id=template_id,
|
||||
)
|
||||
)
|
||||
|
||||
session["scheduled_for"] = request.form.get("scheduled_for", "")
|
||||
|
||||
return render_template(
|
||||
"views/notifications/preview.html",
|
||||
**_check_notification(service_id, template_id),
|
||||
scheduled_for=session["scheduled_for"],
|
||||
recipient=recipient,
|
||||
)
|
||||
|
||||
|
||||
@main.route(
|
||||
"/services/<uuid:service_id>/template/<uuid:template_id>/notification/check",
|
||||
methods=["POST"],
|
||||
)
|
||||
@user_has_permissions("send_messages", restrict_admin_usage=True)
|
||||
def send_notification(service_id, template_id):
|
||||
scheduled_for = session.pop("scheduled_for", "")
|
||||
recipient = get_recipient()
|
||||
if not recipient:
|
||||
return redirect(
|
||||
@@ -868,7 +971,7 @@ def send_notification(service_id, template_id):
|
||||
job_api_client.create_job(
|
||||
upload_id,
|
||||
service_id,
|
||||
scheduled_for=request.form.get("scheduled_for", ""),
|
||||
scheduled_for=scheduled_for,
|
||||
template_id=template_id,
|
||||
original_file_name=filename,
|
||||
notification_count=1,
|
||||
|
||||
Reference in New Issue
Block a user