From ca3fdfd90702b17044204c00d9b1785a9b47d58c Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 27 Feb 2018 11:33:26 +0000 Subject: [PATCH] Check for team members on request to go live page One of the things that we want to check before a service goes live is that they have at least two team members with the manage service permission. Anyone who can make a request to go live has this permission, so that means one additional user is needed. This is what we can automatically communicate to the user. Under the hood this makes use of the logic added in https://github.com/alphagov/notifications-admin/pull/1891 --- app/main/views/service_settings.py | 9 ++++++++- app/templates/components/tick-cross.html | 11 ++++++++--- .../service-settings/request-to-go-live.html | 19 +++++++++++++------ tests/app/main/views/test_service_settings.py | 13 +++++++++++++ 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index 10fb6412a..fcc845654 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -162,7 +162,14 @@ def service_name_change_confirm(service_id): @login_required @user_has_permissions('manage_settings', admin_override=True) def request_to_go_live(service_id): - return render_template('views/service-settings/request-to-go-live.html') + return render_template( + 'views/service-settings/request-to-go-live.html', + has_team_members=( + user_api_client.get_count_of_users_with_permission( + service_id, 'manage_settings' + ) > 1 + ), + ) @main.route("/services//service-settings/submit-request-to-go-live", methods=['GET', 'POST']) diff --git a/app/templates/components/tick-cross.html b/app/templates/components/tick-cross.html index 6467b38ca..f6fbc9ecf 100644 --- a/app/templates/components/tick-cross.html +++ b/app/templates/components/tick-cross.html @@ -1,15 +1,20 @@ -{% macro tick_cross(yes, label) %} +{% macro tick_cross(yes, label, truthy_hint='Can', falsey_hint='Can’t') %}
  • {% if yes %} - Can + {{ truthy_hint }} {{ label}} {% else %} - Can’t + {{ falsey_hint }} {{ label}} {% endif %}
  • {% endmacro %} + + +{% macro tick_cross_done_not_done(yes, label) %} + {{ tick_cross(yes, label, truthy_hint='Done: ', falsey_hint='Not done: ') }} +{% endmacro %} diff --git a/app/templates/views/service-settings/request-to-go-live.html b/app/templates/views/service-settings/request-to-go-live.html index ed8628485..65b1b6ac8 100644 --- a/app/templates/views/service-settings/request-to-go-live.html +++ b/app/templates/views/service-settings/request-to-go-live.html @@ -4,6 +4,7 @@ {% from "components/radios.html" import radios %} {% from "components/page-footer.html" import page_footer %} {% from "components/banner.html" import banner_wrapper %} +{% from "components/tick-cross.html" import tick_cross_done_not_done %} {% block service_page_title %} Request to go live @@ -14,21 +15,27 @@

    Request to go live

    - Before you request to go live, make sure you’ve: + Before you request to go live, make sure that: +

    +
      + {{ tick_cross_done_not_done( + has_team_members, + 'Another person in your team has the ‘Manage service’ permission', + ) }} +
    +

    + You also need to:

    • read our terms of use
    • - added team members to your account -
    • -
    • - specified your reply to email address or text message sender in your + specify your reply to email address or text message sender in your settings page
    • - added the templates you want to start with, making sure they follow the GOV.UK Service Manual standards for + add the templates you want to start with, making sure they follow the GOV.UK Service Manual standards for writing text messages and emails
    diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index e7e945a87..ee0e80387 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -455,17 +455,30 @@ def test_should_raise_duplicate_name_handled( assert mock_verify_password.called +@pytest.mark.parametrize('count_of_users_with_manage_service, expected_checklist_item', [ + (1, 'Not done: Another person in your team has the ‘Manage service’ permission'), + (2, 'Done: Another person in your team has the ‘Manage service’ permission'), +]) def test_should_show_request_to_go_live_checklist( client_request, + mocker, + count_of_users_with_manage_service, + expected_checklist_item, ): + mock_count_users = mocker.patch( + 'app.main.views.service_settings.user_api_client.get_count_of_users_with_permission', + return_value=count_of_users_with_manage_service + ) page = client_request.get( 'main.request_to_go_live', service_id=SERVICE_ONE_ID ) assert page.h1.text == 'Request to go live' + assert normalize_spaces(page.select('main ul li')[0].text) == expected_checklist_item assert page.select_one('main .button')['href'] == url_for( 'main.submit_request_to_go_live', service_id=SERVICE_ONE_ID, ) + mock_count_users.assert_called_once_with(SERVICE_ONE_ID, 'manage_settings') def test_should_show_request_to_go_live(