diff --git a/app/assets/stylesheets/components/banner.scss b/app/assets/stylesheets/components/banner.scss index 18a4ae6db..ae237e56d 100644 --- a/app/assets/stylesheets/components/banner.scss +++ b/app/assets/stylesheets/components/banner.scss @@ -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 { diff --git a/app/main/forms.py b/app/main/forms.py index 188b5b8df..cd255f029 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -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()]) diff --git a/app/main/views/sms.py b/app/main/views/sms.py index 32843cc6e..3a93e1d55 100644 --- a/app/main/views/sms.py +++ b/app/main/views/sms.py @@ -33,15 +33,34 @@ from app.main.utils import ( @main.route("/services//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//sms/send/", 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': diff --git a/app/templates/main_nav.html b/app/templates/main_nav.html index cadc2466b..c4e48051a 100644 --- a/app/templates/main_nav.html +++ b/app/templates/main_nav.html @@ -3,7 +3,7 @@ {{ session.get('service_name', 'Service') }}
    diff --git a/app/templates/views/check-sms.html b/app/templates/views/check-sms.html index aef0b66f0..82c078a46 100644 --- a/app/templates/views/check-sms.html +++ b/app/templates/views/check-sms.html @@ -17,7 +17,7 @@ {% for rejected in upload_result.rejects %}

    Line {{rejected.line_number}}: {{rejected.phone }} {% endfor %} -

    Go back and resolve errors

    +

    Go back and resolve errors

    {% 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) )}} diff --git a/app/templates/views/choose-sms-template.html b/app/templates/views/choose-sms-template.html new file mode 100644 index 000000000..5599cb1e2 --- /dev/null +++ b/app/templates/views/choose-sms-template.html @@ -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 %} +
    + +

    Send text messages

    + + {% if templates %} +
    + {% for template in templates %} + {{ sms_message( + template.content, name=template.name, input_name='template', input_index=template.id + ) }} + {% endfor %} +
    + {{ page_footer("Continue") }} + {% else %} + {{ banner( + 'Add a text message template to start sending messages'.format( + url_for(".add_service_template", service_id=service_id) + )|safe, + type="tip" + )}} + {% endif %} + +
    +{% endblock %} diff --git a/app/templates/views/manage-templates.html b/app/templates/views/manage-templates.html index 32b1512bf..8f8b179ce 100644 --- a/app/templates/views/manage-templates.html +++ b/app/templates/views/manage-templates.html @@ -13,7 +13,7 @@ GOV.UK Notify | Manage templates {{ banner( 'Try sending a text message'.format( - url_for(".send_sms", service_id=service_id) + url_for(".choose_sms_template", service_id=service_id) )|safe, subhead='Next step', type="tip" diff --git a/app/templates/views/send-sms.html b/app/templates/views/send-sms.html index b37e4f61e..039edc7b4 100644 --- a/app/templates/views/send-sms.html +++ b/app/templates/views/send-sms.html @@ -10,34 +10,32 @@ {% block maincolumn_content %}
    -

    Send text messages

    +

    Send text messages

    -
    - 1. Choose text message template - {% for template in templates %} - {{ sms_message( - template.content, name=template.name, input_name='template', input_index=template.id - ) }} - {% endfor %} -
    + {{ sms_message( + template.content, name='Preview' + ) }} -

    2. Add recipients

    {{ banner( - 'You can only send notifications to yourself', - subhead='Trial mode', + 'You can only send messages to yourself until you request to go live'.format( + url_for('.service_request_to_go_live', service_id=service_id) + )|safe, type='info' ) }} -

    - Upload a CSV file to add your recipients’ details. -

    -

    - You can also download an example CSV. -

    +

    {{textbox(form.file)}}

    - {{ page_footer("Continue") }} +

    + Download an example CSV to test with. +

    + + {{ page_footer( + "Continue", + back_link=url_for(".choose_sms_template", service_id=service_id), + back_link_text="Back to templates" + ) }}
    {% endblock %} diff --git a/app/templates/views/service_dashboard.html b/app/templates/views/service_dashboard.html index 08450bcc1..7caa0cb66 100644 --- a/app/templates/views/service_dashboard.html +++ b/app/templates/views/service_dashboard.html @@ -34,7 +34,7 @@ {% else %} {{ banner( 'Try sending a text message'.format( - url_for(".send_sms", service_id=service_id) + url_for(".choose_sms_template", service_id=service_id) )|safe, subhead='Next step', type="tip" diff --git a/tests/app/main/views/test_sms.py b/tests/app/main/views/test_sms.py index 220890f4e..98635d609 100644 --- a/tests/app/main/views/test_sms.py +++ b/tests/app/main/views/test_sms.py @@ -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)