diff --git a/app/assets/stylesheets/app.scss b/app/assets/stylesheets/app.scss index b491feab2..d9ee28958 100644 --- a/app/assets/stylesheets/app.scss +++ b/app/assets/stylesheets/app.scss @@ -252,3 +252,7 @@ details .arrow { color: $secondary-text-colour; cursor: default; } + +.heading-inline { + display: inline-block; +} diff --git a/app/assets/stylesheets/components/banner.scss b/app/assets/stylesheets/components/banner.scss index 584106912..65813e7f9 100644 --- a/app/assets/stylesheets/components/banner.scss +++ b/app/assets/stylesheets/components/banner.scss @@ -76,6 +76,10 @@ } + .list { + margin-bottom: 0; + } + } .banner-tour { diff --git a/app/assets/stylesheets/components/page-footer.scss b/app/assets/stylesheets/components/page-footer.scss index e40c42a35..5354d8901 100644 --- a/app/assets/stylesheets/components/page-footer.scss +++ b/app/assets/stylesheets/components/page-footer.scss @@ -40,6 +40,7 @@ } &-delete-link-without-button { + @include core-19; padding-left: 0; } diff --git a/app/main/views/templates.py b/app/main/views/templates.py index 16ffad266..48e262b2c 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -383,6 +383,44 @@ def delete_service_template(service_id, template_id): ) +@main.route("/services//templates//redact", methods=['GET', 'POST']) +@login_required +@user_has_permissions('manage_templates', admin_override=True) +def redact_template(service_id, template_id): + + if request.method == 'POST': + + service_api_client.redact_service_template(service_id, template_id) + + flash( + 'Personalised content will be hidden for messages sent with this template', + 'default_with_tick' + ) + + return redirect(url_for( + '.view_template', + service_id=service_id, + template_id=template_id, + )) + + return render_template( + 'views/templates/template.html', + template=get_template( + service_api_client.get_service_template(service_id, template_id)['data'], + current_service, + expand_emails=True, + letter_preview_url=url_for( + '.view_letter_template_preview', + service_id=service_id, + template_id=template_id, + filetype='png', + ), + show_recipient=True, + ), + show_redaction_message=True, + ) + + @main.route('/services//templates//versions') @login_required @user_has_permissions( diff --git a/app/notify_client/service_api_client.py b/app/notify_client/service_api_client.py index 30511b27b..96351ab71 100644 --- a/app/notify_client/service_api_client.py +++ b/app/notify_client/service_api_client.py @@ -168,6 +168,12 @@ class ServiceAPIClient(NotifyAdminAPIClient): endpoint = "/service/{0}/template/{1}".format(service_id, id_) return self.post(endpoint, data) + def redact_service_template(self, service_id, id_): + return self.post( + "/service/{}/template/{}".format(service_id, id_), + {'redact_personalisation': True} + ) + def get_service_template(self, service_id, template_id, version=None, *params): """ Retrieve a service template. diff --git a/app/templates/views/templates/template.html b/app/templates/views/templates/template.html index ab564ef2b..8465224e2 100644 --- a/app/templates/views/templates/template.html +++ b/app/templates/views/templates/template.html @@ -1,4 +1,5 @@ {% extends "withnav_template.html" %} +{% from "components/banner.html" import banner_wrapper %} {% from "components/page-footer.html" import page_footer %} {% from "components/textbox.html" import textbox %} {% from "components/api-key.html" import api_key %} @@ -9,6 +10,24 @@ {% block maincolumn_content %} + {% if show_redaction_message %} +
+ {% call banner_wrapper(type='dangerous', subhead='Are you sure you want to hide personalisation after sending?') %} +
    +
  • + You won’t be able to see personalised content in Notify for this template +
  • +
  • + You can’t undo this +
  • +
+
+ + +
+ {% endcall %} +
+ {% endif %}

{{ template.name }}

@@ -18,26 +37,29 @@ {% endwith %} -
+
{{ api_key(template.id, name="Template ID", thing='template ID') }}
- {% if template._template.updated_at %} -
-

Last edited {{ template._template.updated_at|format_delta }}

-

- See previous versions -

-
- {% endif %} - - {% if current_user.has_permissions(permissions=['manage_templates'], admin_override=True) %} -
- {{ page_footer( - delete_link=url_for('.delete_service_template', service_id=current_service.id, template_id=template.id), - delete_link_text='Delete this template' - ) }} -
- {% endif %} +
+ {% if template._template.updated_at %} +

Last edited {{ template._template.updated_at|format_delta }}

+   + See previous versions +   +
+ {% endif %} + {% if current_user.has_permissions(permissions=['manage_templates'], admin_override=True) %} + + Delete this template + +   + {% if not template.redact_personalisation %} + + Hide personalisation after sending + + {% endif %} + {% endif %} +
{% endblock %} diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py index 780ecca78..6fea6d70f 100644 --- a/tests/app/main/views/test_templates.py +++ b/tests/app/main/views/test_templates.py @@ -942,3 +942,48 @@ def test_should_create_sms_template_without_downgrading_unicode_characters( ANY # process_type ) assert resp.status_code == 302 + + +def test_should_show_message_before_redacting_template( + client_request, + mock_get_service_template, + service_one, + fake_uuid, +): + + page = client_request.get( + 'main.redact_template', + service_id=SERVICE_ONE_ID, + template_id=fake_uuid, + ) + + assert ( + 'Are you sure you want to hide personalisation after sending?' + ) in page.select('.banner-dangerous')[0].text + + form = page.select('.banner-dangerous form')[0] + + assert 'action' not in form + assert form['method'] == 'post' + + +def test_should_show_redact_template( + client_request, + mock_get_service_template, + mock_redact_template, + service_one, + fake_uuid, +): + + page = client_request.post( + 'main.redact_template', + service_id=SERVICE_ONE_ID, + template_id=fake_uuid, + _follow_redirects=True, + ) + + assert normalize_spaces(page.select('.banner-default-with-tick')[0].text) == ( + 'Personalised content will be hidden for messages sent with this template' + ) + + mock_redact_template.assert_called_once_with(SERVICE_ONE_ID, fake_uuid) diff --git a/tests/conftest.py b/tests/conftest.py index 324038f27..19fd28b09 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -518,6 +518,11 @@ def mock_delete_service_template(mocker): 'app.service_api_client.delete_service_template', side_effect=_delete) +@pytest.fixture(scope='function') +def mock_redact_template(mocker): + return mocker.patch('app.service_api_client.redact_service_template') + + @pytest.fixture(scope='function') def api_user_pending(fake_uuid): from app.notify_client.user_api_client import User