diff --git a/app/config.py b/app/config.py index 2baf45576..1175e8861 100644 --- a/app/config.py +++ b/app/config.py @@ -39,6 +39,11 @@ class Config(object): 'central': 250000, 'local': 25000, 'nhs': 25000, + 'nhs_central': 250000, + 'nhs_local': 25000, + 'emergency_service': 25000, + 'school_or_college': 25000, + 'other': 25000, } EMAIL_EXPIRY_SECONDS = 3600 # 1 hour INVITATION_EXPIRY_SECONDS = 3600 * 24 * 2 # 2 days - also set on api diff --git a/app/main/forms.py b/app/main/forms.py index 38290cb73..5d840462a 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -248,7 +248,24 @@ def organisation_type(label='Who runs this service?'): choices=[ ('central', 'Central government'), ('local', 'Local government'), - ('nhs', 'NHS'), + ('nhs_central', 'NHS – central government agency or public body'), + ('nhs_local', 'NHS Trust or Clinical Commissioning Group'), + ('nhs_local', 'GP practice'), + ('emergency_service', 'Emergency service'), + ('school_or_college', 'School or college'), + ('other', 'Other'), + ], + validators=[DataRequired()], + ) + + +def nhs_organisation_type(label='Who runs this service?'): + return RadioField( + label, + choices=[ + ('nhs_central', 'NHS – central government agency or public body'), + ('nhs_local', 'NHS Trust or Clinical Commissioning Group'), + ('nhs_local', 'GP practice'), ], validators=[DataRequired()], ) @@ -584,13 +601,17 @@ class OrganisationDomainsForm(StripWhitespaceForm): class CreateServiceForm(StripWhitespaceForm): name = StringField( - u'What’s your service called?', + "What’s your service called?", validators=[ DataRequired(message='Can’t be empty') ]) organisation_type = organisation_type() +class CreateNhsServiceForm(CreateServiceForm): + organisation_type = nhs_organisation_type() + + class NewOrganisationForm( RenameOrganisationForm, OrganisationOrganisationTypeForm, diff --git a/app/main/views/add_service.py b/app/main/views/add_service.py index 86019caa1..b1b726189 100644 --- a/app/main/views/add_service.py +++ b/app/main/views/add_service.py @@ -4,7 +4,7 @@ from notifications_python_client.errors import HTTPError from app import billing_api_client, service_api_client from app.main import main -from app.main.forms import CreateServiceForm +from app.main.forms import CreateNhsServiceForm, CreateServiceForm from app.utils import email_safe, user_is_gov_user, user_is_logged_in @@ -47,9 +47,14 @@ def _create_example_template(service_id): @user_is_logged_in @user_is_gov_user def add_service(): - form = CreateServiceForm( - organisation_type=current_user.default_organisation_type - ) + default_organisation_type = current_user.default_organisation_type + if default_organisation_type == 'nhs': + form = CreateNhsServiceForm() + default_organisation_type = None + else: + form = CreateServiceForm( + organisation_type=default_organisation_type + ) heading = 'About your service' if form.validate_on_submit(): @@ -58,7 +63,7 @@ def add_service(): service_id, error = _create_service( service_name, - current_user.default_organisation_type or form.organisation_type.data, + default_organisation_type or form.organisation_type.data, email_from, form, ) @@ -72,11 +77,12 @@ def add_service(): return redirect(url_for( 'main.start_tour', service_id=service_id, - template_id=example_sms_template['data']['id'], + template_id=example_sms_template['data']['id'] )) else: return render_template( 'views/add-service.html', form=form, - heading=heading + heading=heading, + default_organisation_type=default_organisation_type, ) diff --git a/app/models/service.py b/app/models/service.py index e9c9de6a5..7e7662b20 100644 --- a/app/models/service.py +++ b/app/models/service.py @@ -268,7 +268,7 @@ class Service(JSONModel): @property def shouldnt_use_govuk_as_sms_sender(self): - return self.organisation_type in {'local', 'nhs'} + return self.organisation_type != 'central' @cached_property def sms_senders(self): diff --git a/app/templates/views/add-service.html b/app/templates/views/add-service.html index b284e972e..adf2191cc 100644 --- a/app/templates/views/add-service.html +++ b/app/templates/views/add-service.html @@ -20,7 +20,7 @@ {{ textbox(form.name, hint="You can change this later") }} - {% if not current_user.default_organisation_type %} + {% if not default_organisation_type %} {{ radios(form.organisation_type) }} {% endif %} diff --git a/app/templates/views/organisations/organisation/settings/index.html b/app/templates/views/organisations/organisation/settings/index.html index 5708deeed..ce5e4f342 100644 --- a/app/templates/views/organisations/organisation/settings/index.html +++ b/app/templates/views/organisations/organisation/settings/index.html @@ -29,6 +29,11 @@ 'central': 'Central government', 'local': 'Local government', 'nhs': 'NHS', + 'nhs_central': 'NHS – central government agency or public body', + 'nhs_local': 'NHS Trust, GP practice or Clinical Commissioning Group', + 'emergency_service': 'Emergency service', + 'school_or_college': 'School or college', + 'other': 'Other', }.get(current_org.organisation_type)) }} {{ edit_field( 'Change', diff --git a/app/templates/views/service-settings.html b/app/templates/views/service-settings.html index 7cc16eadd..bc750e825 100644 --- a/app/templates/views/service-settings.html +++ b/app/templates/views/service-settings.html @@ -322,6 +322,11 @@ 'central': 'Central government', 'local': 'Local government', 'nhs': 'NHS', + 'nhs_central': 'NHS – central government agency or public body', + 'nhs_local': 'NHS Trust, GP practice or Clinical Commissioning Group', + 'emergency_service': 'Emergency service', + 'school_or_college': 'School or college', + 'other': 'Other' }.get(current_service.organisation_type) }} {% endif %} diff --git a/tests/app/main/views/organisations/test_organisation.py b/tests/app/main/views/organisations/test_organisation.py index 6ca33206e..7e5eb5d34 100644 --- a/tests/app/main/views/organisations/test_organisation.py +++ b/tests/app/main/views/organisations/test_organisation.py @@ -90,7 +90,12 @@ def test_page_to_create_new_organisation( ('text', 'name', ''), ('radio', 'organisation_type', 'central'), ('radio', 'organisation_type', 'local'), - ('radio', 'organisation_type', 'nhs'), + ('radio', 'organisation_type', 'nhs_central'), + ('radio', 'organisation_type', 'nhs_local'), + ('radio', 'organisation_type', 'nhs_local'), + ('radio', 'organisation_type', 'emergency_service'), + ('radio', 'organisation_type', 'school_or_college'), + ('radio', 'organisation_type', 'other'), ('radio', 'crown_status', 'crown'), ('radio', 'crown_status', 'non-crown'), ('hidden', 'csrf_token', ANY), @@ -275,7 +280,12 @@ def test_organisation_settings_for_platform_admin( ( ('central', 'Central government'), ('local', 'Local government'), - ('nhs', 'NHS'), + ('nhs_central', 'NHS – central government agency or public body'), + ('nhs_local', 'NHS Trust or Clinical Commissioning Group'), + ('nhs_local', 'GP practice'), + ('emergency_service', 'Emergency service'), + ('school_or_college', 'School or college'), + ('other', 'Other'), ), None, ), @@ -358,8 +368,8 @@ def test_view_organisation_settings( ), ( '.edit_organisation_type', - {'organisation_type': 'nhs'}, - {'organisation_type': 'nhs'}, + {'organisation_type': 'nhs_local'}, + {'organisation_type': 'nhs_local'}, ), ( '.edit_organisation_crown_status', diff --git a/tests/app/main/views/test_add_service.py b/tests/app/main/views/test_add_service.py index c3ff1c1d9..2a6910067 100644 --- a/tests/app/main/views/test_add_service.py +++ b/tests/app/main/views/test_add_service.py @@ -41,14 +41,24 @@ def test_get_should_render_add_service_template( ] == [ 'Central government', 'Local government', - 'NHS', + 'NHS – central government agency or public body', + 'NHS Trust or Clinical Commissioning Group', + 'GP practice', + 'Emergency service', + 'School or college', + 'Other', ] assert [ radio['value'] for radio in page.select('.multiple-choice input') ] == [ 'central', 'local', - 'nhs', + 'nhs_central', + 'nhs_local', + 'nhs_local', + 'emergency_service', + 'school_or_college', + 'other', ] @@ -71,8 +81,12 @@ def test_get_should_not_render_radios_if_org_type_known( @pytest.mark.parametrize('inherited, posted, persisted, sms_limit', ( (None, 'central', 'central', 250000), ('central', None, 'central', 250000), - ('nhs', None, 'nhs', 25000), + ('nhs_central', None, 'nhs_central', 250000), + ('nhs_local', None, 'nhs_local', 25000), ('local', None, 'local', 25000), + ('emergency_service', None, 'emergency_service', 25000), + ('school_or_college', None, 'school_or_college', 25000), + ('other', None, 'other', 25000), ('central', 'local', 'central', 250000), )) def test_should_add_service_and_redirect_to_tour_when_no_services( @@ -163,20 +177,11 @@ def test_add_service_has_to_choose_org_type( 'test@nhs.uk', 'test@example.NhS.uK', 'test@EXAMPLE.NHS.NET', - pytest.param( - 'test@not-nhs.uk', - marks=pytest.mark.xfail(raises=AssertionError) - ) )) -def test_add_service_guesses_org_type_for_unknown_nhs_orgs( - mocker, +def test_get_should_only_show_nhs_org_types_radios_if_user_has_nhs_email( client_request, - mock_create_service, - mock_create_service_template, - mock_get_services_with_no_services, + mocker, api_user_active, - mock_create_or_update_free_sms_fragment_limit, - mock_get_all_email_branding, email_address, ): api_user_active['email_address'] = email_address @@ -185,17 +190,33 @@ def test_add_service_guesses_org_type_for_unknown_nhs_orgs( 'app.organisations_client.get_organisation_by_domain', return_value=None, ) - client_request.post( - 'main.add_service', - _data={'name': 'example'}, - ) - assert mock_create_service.call_args[1]['organisation_type'] == 'nhs' + page = client_request.get('main.add_service') + assert page.select_one('h1').text.strip() == 'About your service' + assert page.select_one('input[name=name]')['value'] == '' + assert [ + label.text.strip() for label in page.select('.multiple-choice label') + ] == [ + 'NHS – central government agency or public body', + 'NHS Trust or Clinical Commissioning Group', + 'GP practice', + ] + assert [ + radio['value'] for radio in page.select('.multiple-choice input') + ] == [ + 'nhs_central', + 'nhs_local', + 'nhs_local', + ] @pytest.mark.parametrize('organisation_type, free_allowance', [ ('central', 250 * 1000), ('local', 25 * 1000), - ('nhs', 25 * 1000), + ('nhs_central', 250 * 1000), + ('nhs_local', 25 * 1000), + ('school_or_college', 25 * 1000), + ('emergency_service', 25 * 1000), + ('other', 25 * 1000), ]) def test_should_add_service_and_redirect_to_dashboard_when_existing_service( app_, diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index f20ec3f93..c45d2777c 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -900,7 +900,7 @@ def test_should_not_show_go_live_button_if_checklist_not_complete( ), pytest.param( 1, - None, + 'central', 99, [{'is_default': True, 'sms_sender': 'GOVUK'}], '', @@ -931,14 +931,14 @@ def test_should_not_show_go_live_button_if_checklist_not_complete( ), ( 1, - 'local', + 'nhs_local', 0, [], 'Change your text message sender name Not completed', ), ( None, - 'local', + 'school_or_college', 1, [{'is_default': True, 'sms_sender': 'GOVUK'}], 'Change your text message sender name Not completed', @@ -955,7 +955,7 @@ def test_should_not_show_go_live_button_if_checklist_not_complete( ), ( None, - 'nhs', + 'nhs_local', 1, [{'is_default': True, 'sms_sender': 'KUVOG'}], 'Change your text message sender name Completed',