From 1f278bdd077721da692ccbf22641effe0b63bd4d Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 3 Apr 2017 09:54:03 +0100 Subject: [PATCH] Go back to template after editing contact details MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Users who go to edit the contact details for a letter from the template page get very confused when they click save and are dumped on the settings page. It doesn’t match the way editing other parts of letter works, and you can’t see an accurate preview of the changes from the settings page. So this commit changes the flow to go from the _edit contact details_ page back to the _view template_ page when the user has got there by clicking the blue _Edit_ button on the _view template_ page. --- app/main/views/service_settings.py | 4 +++ app/templates/views/templates/_template.html | 2 +- tests/app/main/views/test_service_settings.py | 25 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index 5c8f83ae3..abc6dd620 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -275,6 +275,10 @@ def service_set_letter_contact_block(service_id): current_service['id'], letter_contact_block=form.letter_contact_block.data.replace('\r', '') or None ) + if request.args.get('from_template'): + return redirect( + url_for('.view_template', service_id=service_id, template_id=request.args.get('from_template')) + ) return redirect(url_for('.service_settings', service_id=service_id)) return render_template( 'views/service-settings/set-letter-contact-block.html', diff --git a/app/templates/views/templates/_template.html b/app/templates/views/templates/_template.html index f7c05eac9..76e533474 100644 --- a/app/templates/views/templates/_template.html +++ b/app/templates/views/templates/_template.html @@ -35,7 +35,7 @@
{% if current_user.has_permissions(permissions=['manage_templates'], admin_override=True) and template.template_type == 'letter' %} Edit - Edit + Edit Edit {% endif %} {{ template|string }} diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index 9fd2b4252..dfcbac884 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -1,6 +1,7 @@ from unittest.mock import call, ANY, Mock import pytest +import uuid from flask import url_for from bs4 import BeautifulSoup from werkzeug.exceptions import InternalServerError @@ -619,6 +620,30 @@ def test_set_letter_contact_block_saves( mock_update_service.assert_called_once_with(service_one['id'], letter_contact_block='foo bar baz waz') +def test_set_letter_contact_block_redirects_to_template( + logged_in_client, + service_one, + mock_update_service, +): + service_one['can_send_letters'] = True + fake_template_id = uuid.uuid4() + response = logged_in_client.post( + url_for( + 'main.service_set_letter_contact_block', + service_id=service_one['id'], + from_template=fake_template_id, + ), + data={'letter_contact_block': ''}, + ) + assert response.status_code == 302 + assert response.location == url_for( + 'main.view_template', + service_id=service_one['id'], + template_id=fake_template_id, + _external=True, + ) + + def test_set_letter_contact_block_has_max_10_lines( logged_in_client, service_one,