From 147ea7517791f8149ea16f017bfcdcc0b232a984 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 6 Aug 2018 11:09:07 +0100 Subject: [PATCH] Skip template page for users who only send MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If you only send messages then there’s no longer much point in the template page. It now, for you, only has one action – ‘Send’. This commit changes the journey for these users so they go straight from clicking the name of the template to the page where you enter the phone number or email address. This is better because it reduces the number of steps a user has to click through to send a message. This journey is what we were previously calling ‘basic view’. But this changes makes it automatically available to anyone who would benefit from it. It removes the complexity of: - having to opt in to basic view at a service level - having to choose on a per-user basis who has basic view - understanding the nuance between basic view and only choosing the ‘Send messages’ permission Users who will still see the template page are: - those who can edit templates – they need the ‘edit’ link - users with the manage API keys permission – they need a place to get the template ID --- app/main/views/templates.py | 5 ++++- tests/app/main/views/test_templates.py | 31 +++++++++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/app/main/views/templates.py b/app/main/views/templates.py index 732023f65..16b18cf59 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -48,7 +48,10 @@ page_headings = { @login_required @user_has_permissions('view_activity', 'send_messages') def view_template(service_id, template_id): - if not current_user.has_permissions('view_activity'): + if ( + current_user.has_permissions('send_messages') and + not current_user.has_permissions('manage_templates', 'manage_api_keys') + ): return redirect(url_for( '.send_one_off', service_id=service_id, template_id=template_id )) diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py index 0d7215b33..b2c28df84 100644 --- a/tests/app/main/views/test_templates.py +++ b/tests/app/main/views/test_templates.py @@ -187,6 +187,32 @@ def test_caseworker_redirected_to_one_off( ) +def test_user_with_only_send_and_view_redirected_to_one_off( + client_request, + mock_get_service_templates, + active_user_with_permissions, + mocker, + fake_uuid, +): + active_user_with_permissions._permissions[SERVICE_ONE_ID] = [ + 'send_messages', + 'view_activity', + ] + client_request.login(active_user_with_permissions) + client_request.get( + 'main.view_template', + service_id=SERVICE_ONE_ID, + template_id=fake_uuid, + _expected_status=302, + _expected_redirect=url_for( + 'main.send_one_off', + service_id=SERVICE_ONE_ID, + template_id=fake_uuid, + _external=True, + ), + ) + + @pytest.mark.parametrize('permissions, links_to_be_shown, permissions_warning_to_be_shown', [ ( ['view_activity'], @@ -203,11 +229,6 @@ def test_caseworker_redirected_to_one_off( ['.edit_service_template'], None, ), - ( - ['send_messages'], - ['.set_sender'], - None, - ), ( ['send_messages', 'manage_templates'], ['.set_sender', '.edit_service_template'],