mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 02:42:26 -05:00
Merge pull request #147 from alphagov/split-sms
Split ‘send SMS’ page into two pages
This commit is contained in:
@@ -33,6 +33,16 @@
|
||||
@extend .banner;
|
||||
background: $govuk-blue;
|
||||
color: $white;
|
||||
|
||||
a:link, a:visited {
|
||||
color: $white;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: $light-blue-25;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.banner-dangerous {
|
||||
|
||||
@@ -217,7 +217,7 @@ class ChangePasswordForm(Form):
|
||||
|
||||
|
||||
class CsvUploadForm(Form):
|
||||
file = FileField('File to upload', validators=[DataRequired(
|
||||
file = FileField('Upload a CSV file to add your recipients’ details', validators=[DataRequired(
|
||||
message='Please pick a file'), CsvFileValidator()])
|
||||
|
||||
|
||||
|
||||
@@ -33,15 +33,34 @@ from app.main.utils import (
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/sms/send", methods=['GET', 'POST'])
|
||||
def choose_sms_template(service_id):
|
||||
if request.method == 'POST':
|
||||
return redirect(url_for('.send_sms',
|
||||
service_id=service_id,
|
||||
template_id=request.form.get('template')))
|
||||
|
||||
try:
|
||||
templates = templates_dao.get_service_templates(service_id)['data']
|
||||
except HTTPError as e:
|
||||
if e.status_code == 404:
|
||||
abort(404)
|
||||
else:
|
||||
raise e
|
||||
|
||||
return render_template('views/choose-sms-template.html',
|
||||
templates=templates,
|
||||
service_id=service_id)
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/sms/send/<template_id>", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def send_sms(service_id):
|
||||
def send_sms(service_id, template_id):
|
||||
form = CsvUploadForm()
|
||||
if form.validate_on_submit():
|
||||
try:
|
||||
csv_file = form.file.data
|
||||
filedata = _get_filedata(csv_file)
|
||||
upload_id = str(uuid.uuid4())
|
||||
template_id = request.form.get('template')
|
||||
s3upload(upload_id, service_id, filedata, current_app.config['AWS_REGION'])
|
||||
session['upload_data'] = {"template_id": template_id, "original_file_name": filedata['file_name']}
|
||||
return redirect(url_for('.check_sms',
|
||||
@@ -52,10 +71,10 @@ def send_sms(service_id):
|
||||
csv_file.filename)
|
||||
flash(message)
|
||||
flash(str(e))
|
||||
return redirect(url_for('.send_sms', service_id=service_id))
|
||||
return redirect(url_for('.send_sms', service_id=service_id, template_id=template_id))
|
||||
|
||||
try:
|
||||
templates = templates_dao.get_service_templates(service_id)['data']
|
||||
template = templates_dao.get_service_template(service_id, template_id)['data']
|
||||
except HTTPError as e:
|
||||
if e.status_code == 404:
|
||||
abort(404)
|
||||
@@ -63,7 +82,7 @@ def send_sms(service_id):
|
||||
raise e
|
||||
|
||||
return render_template('views/send-sms.html',
|
||||
templates=templates,
|
||||
template=template,
|
||||
form=form,
|
||||
service_id=service_id)
|
||||
|
||||
@@ -84,6 +103,7 @@ def check_sms(service_id, upload_id):
|
||||
'views/check-sms.html',
|
||||
upload_result=upload_result,
|
||||
message_template=template['content'],
|
||||
template_id=template_id,
|
||||
service_id=service_id
|
||||
)
|
||||
elif request.method == 'POST':
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<a href="{{ url_for('.service_dashboard', service_id=service_id) }}">{{ session.get('service_name', 'Service') }}</a>
|
||||
</h2>
|
||||
<ul>
|
||||
<li><a href="{{ url_for('.send_sms', service_id=service_id) }}">Send text messages</a></li>
|
||||
<li><a href="{{ url_for('.choose_sms_template', service_id=service_id) }}">Send text messages</a></li>
|
||||
<li><a href="{{ url_for('.send_email', service_id=service_id) }}">Send emails</a></li>
|
||||
</ul>
|
||||
<ul>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
{% for rejected in upload_result.rejects %}
|
||||
<p>Line {{rejected.line_number}}: {{rejected.phone }}</a>
|
||||
{% endfor %}
|
||||
<p><a href="{{url_for('.send_sms', service_id=service_id)}}" class="button">Go back and resolve errors</a></p>
|
||||
<p><a href="{{url_for('.send_sms', service_id=service_id, template_id=template_id)}}" class="button">Go back and resolve errors</a></p>
|
||||
|
||||
{% else %}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
{{ page_footer(
|
||||
button_text = "Send {} text messages".format(upload_result.valid|count),
|
||||
back_link = url_for(".send_sms", service_id=service_id)
|
||||
back_link = url_for(".send_sms", service_id=service_id, template_id=template_id)
|
||||
)}}
|
||||
|
||||
{% if upload_result.valid | count > 6 %}
|
||||
@@ -56,7 +56,7 @@
|
||||
|
||||
{{ page_footer(
|
||||
button_text = "Send {} text messages".format(upload_result.valid|count),
|
||||
back_link = url_for(".send_sms", service_id=service_id)
|
||||
back_link = url_for(".send_sms", service_id=service_id, template_id=template_id)
|
||||
)}}
|
||||
|
||||
</form>
|
||||
|
||||
34
app/templates/views/choose-sms-template.html
Normal file
34
app/templates/views/choose-sms-template.html
Normal file
@@ -0,0 +1,34 @@
|
||||
{% extends "withnav_template.html" %}
|
||||
{% from "components/sms-message.html" import sms_message %}
|
||||
{% from "components/page-footer.html" import page_footer %}
|
||||
{% from "components/textbox.html" import textbox %}
|
||||
|
||||
{% block page_title %}
|
||||
GOV.UK Notify | Send text messages
|
||||
{% endblock %}
|
||||
|
||||
{% block maincolumn_content %}
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
|
||||
<h1 class="heading-large">Send text messages</h1>
|
||||
|
||||
{% if templates %}
|
||||
<fieldset class='form-group'>
|
||||
{% for template in templates %}
|
||||
{{ sms_message(
|
||||
template.content, name=template.name, input_name='template', input_index=template.id
|
||||
) }}
|
||||
{% endfor %}
|
||||
</fieldset>
|
||||
{{ page_footer("Continue") }}
|
||||
{% else %}
|
||||
{{ banner(
|
||||
'<a href="{}">Add a text message template</a> to start sending messages'.format(
|
||||
url_for(".add_service_template", service_id=service_id)
|
||||
)|safe,
|
||||
type="tip"
|
||||
)}}
|
||||
{% endif %}
|
||||
|
||||
</form>
|
||||
{% endblock %}
|
||||
@@ -13,7 +13,7 @@ GOV.UK Notify | Manage templates
|
||||
|
||||
{{ banner(
|
||||
'<a href="{}">Try sending a text message</a>'.format(
|
||||
url_for(".send_sms", service_id=service_id)
|
||||
url_for(".choose_sms_template", service_id=service_id)
|
||||
)|safe,
|
||||
subhead='Next step',
|
||||
type="tip"
|
||||
|
||||
@@ -10,34 +10,32 @@
|
||||
{% block maincolumn_content %}
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
|
||||
<h1 class="heading-large">Send text messages</h1>
|
||||
<h1 class="heading-large">Send text messages</h1>
|
||||
|
||||
<fieldset class='form-group'>
|
||||
<legend class="heading-medium">1. Choose text message template</legend>
|
||||
{% for template in templates %}
|
||||
{{ sms_message(
|
||||
template.content, name=template.name, input_name='template', input_index=template.id
|
||||
) }}
|
||||
{% endfor %}
|
||||
</fieldset>
|
||||
{{ sms_message(
|
||||
template.content, name='Preview'
|
||||
) }}
|
||||
|
||||
<h2 class="heading-medium">2. Add recipients</h2>
|
||||
{{ banner(
|
||||
'You can only send notifications to yourself',
|
||||
subhead='Trial mode',
|
||||
'You can only send messages to yourself until you <a href="{}">request to go live</a>'.format(
|
||||
url_for('.service_request_to_go_live', service_id=service_id)
|
||||
)|safe,
|
||||
type='info'
|
||||
) }}
|
||||
<p>
|
||||
Upload a CSV file to add your recipients’ details.
|
||||
</p>
|
||||
<p>
|
||||
You can also <a href="#">download an example CSV</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
{{textbox(form.file)}}
|
||||
</p>
|
||||
|
||||
{{ page_footer("Continue") }}
|
||||
<p>
|
||||
<a href="#">Download an example CSV</a> to test with.
|
||||
</p>
|
||||
|
||||
{{ page_footer(
|
||||
"Continue",
|
||||
back_link=url_for(".choose_sms_template", service_id=service_id),
|
||||
back_link_text="Back to templates"
|
||||
) }}
|
||||
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
{% else %}
|
||||
{{ banner(
|
||||
'<a href="{}">Try sending a text message</a>'.format(
|
||||
url_for(".send_sms", service_id=service_id)
|
||||
url_for(".choose_sms_template", service_id=service_id)
|
||||
)|safe,
|
||||
subhead='Next step',
|
||||
type="tip"
|
||||
|
||||
@@ -4,16 +4,54 @@ from flask import url_for
|
||||
import moto
|
||||
|
||||
|
||||
def test_choose_sms_template(app_,
|
||||
api_user_active,
|
||||
mock_get_user,
|
||||
mock_get_service_templates,
|
||||
mock_check_verify_code,
|
||||
mock_get_service_template):
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
client.login(api_user_active)
|
||||
response = client.get(url_for('main.choose_sms_template', service_id=12345))
|
||||
|
||||
assert response.status_code == 200
|
||||
content = response.get_data(as_text=True)
|
||||
assert 'template_one' in content
|
||||
assert 'template one content' in content
|
||||
assert 'template_two' in content
|
||||
assert 'template two content' in content
|
||||
|
||||
|
||||
def test_choose_sms_template_redirects(app_,
|
||||
api_user_active,
|
||||
mock_get_user,
|
||||
mock_get_service_templates,
|
||||
mock_check_verify_code,
|
||||
mock_get_service_template):
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
client.login(api_user_active)
|
||||
response = client.post(
|
||||
url_for('main.choose_sms_template', service_id=12345),
|
||||
data={'template': '54321'}
|
||||
)
|
||||
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for('main.send_sms', service_id=12345, template_id=54321, _external=True)
|
||||
|
||||
|
||||
def test_upload_empty_csvfile_returns_to_upload_page(app_,
|
||||
api_user_active,
|
||||
mock_get_user,
|
||||
mock_get_service_templates,
|
||||
mock_check_verify_code):
|
||||
mock_check_verify_code,
|
||||
mock_get_service_template):
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
client.login(api_user_active)
|
||||
upload_data = {'file': (BytesIO(''.encode('utf-8')), 'emtpy.csv')}
|
||||
response = client.post(url_for('main.send_sms', service_id=123),
|
||||
response = client.post(url_for('main.send_sms', service_id=12345, template_id=54321),
|
||||
data=upload_data, follow_redirects=True)
|
||||
|
||||
assert response.status_code == 200
|
||||
@@ -37,7 +75,7 @@ def test_upload_csvfile_with_invalid_phone_shows_check_page_with_errors(app_,
|
||||
with app_.test_client() as client:
|
||||
client.login(api_user_active)
|
||||
upload_data = {'file': file_data}
|
||||
response = client.post(url_for('main.send_sms', service_id=123),
|
||||
response = client.post(url_for('main.send_sms', service_id=12345, template_id=54321),
|
||||
data=upload_data,
|
||||
follow_redirects=True)
|
||||
assert response.status_code == 200
|
||||
@@ -64,7 +102,7 @@ def test_upload_csvfile_with_valid_phone_shows_first3_and_last3_numbers(app_,
|
||||
with app_.test_client() as client:
|
||||
client.login(api_user_active)
|
||||
upload_data = {'file': file_data}
|
||||
response = client.post(url_for('main.send_sms', service_id=123),
|
||||
response = client.post(url_for('main.send_sms', service_id=12345, template_id=54321),
|
||||
data=upload_data,
|
||||
follow_redirects=True)
|
||||
|
||||
@@ -102,7 +140,7 @@ def test_upload_csvfile_with_valid_phone_shows_all_if_6_or_less_numbers(app_,
|
||||
with app_.test_client() as client:
|
||||
client.login(api_user_active)
|
||||
upload_data = {'file': file_data}
|
||||
response = client.post(url_for('main.send_sms', service_id=123),
|
||||
response = client.post(url_for('main.send_sms', service_id=12345, template_id=54321),
|
||||
data=upload_data,
|
||||
follow_redirects=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user