Add page to change organisation type

If a user picks the wrong thing, we should be able to override it when
they go live.
This commit is contained in:
Chris Hill-Scott
2017-10-23 17:45:44 +01:00
parent 8cc8a0bf05
commit d438109630
5 changed files with 133 additions and 12 deletions
+17 -9
View File
@@ -141,6 +141,18 @@ def sms_code():
message='Code not found')]) message='Code not found')])
def organisation_type():
return RadioField(
'Who runs this service?',
choices=[
('central', 'Central government'),
('local', 'Local government'),
('nhs', 'NHS'),
],
validators=[DataRequired()],
)
class LoginForm(Form): class LoginForm(Form):
email_address = StringField('Email address', validators=[ email_address = StringField('Email address', validators=[
Length(min=5, max=255), Length(min=5, max=255),
@@ -227,15 +239,11 @@ class CreateServiceForm(Form):
validators=[ validators=[
DataRequired(message='Cant be empty') DataRequired(message='Cant be empty')
]) ])
organisation_type = RadioField( organisation_type = organisation_type()
'Who runs this service?',
choices=[
('central', 'Central government'), class OrganisationTypeForm(Form):
('local', 'Local government'), organisation_type = organisation_type()
('nhs', 'NHS'),
],
validators=[DataRequired()],
)
class ConfirmPasswordForm(Form): class ConfirmPasswordForm(Form):
+23
View File
@@ -34,6 +34,7 @@ from app.main.forms import (
LetterBranding, LetterBranding,
ServiceInboundApiForm, ServiceInboundApiForm,
InternationalSMSForm, InternationalSMSForm,
OrganisationTypeForm,
) )
from app import user_api_client, current_service, organisations_client, inbound_number_client from app import user_api_client, current_service, organisations_client, inbound_number_client
from notifications_utils.formatters import formatted_list from notifications_utils.formatters import formatted_list
@@ -574,6 +575,28 @@ def service_set_letter_contact_block(service_id):
) )
@main.route("/services/<service_id>/service-settings/set-organisation-type", methods=['GET', 'POST'])
@login_required
@user_has_permissions(admin_override=True)
def set_organisation_type(service_id):
form = OrganisationTypeForm(organisation_type=current_service.get('organisation_type'))
if form.validate_on_submit():
service_api_client.update_service(
service_id,
organisation_type=form.organisation_type.data,
)
return redirect(url_for('.service_settings', service_id=service_id))
form.organisation_type.data = current_service.get('organisation_type')
return render_template(
'views/service-settings/set-organisation-type.html',
form=form,
)
@main.route("/services/<service_id>/service-settings/set-branding-and-org", methods=['GET', 'POST']) @main.route("/services/<service_id>/service-settings/set-branding-and-org", methods=['GET', 'POST'])
@login_required @login_required
@user_has_permissions(admin_override=True) @user_has_permissions(admin_override=True)
+1 -1
View File
@@ -193,7 +193,7 @@
{{ optional_text_field( {{ optional_text_field(
(current_service.organisation_type or '')|title (current_service.organisation_type or '')|title
) }} ) }}
{{ text_field() }} {{ edit_field('Change', url_for('.set_organisation_type', service_id=current_service.id)) }}
{% endcall %} {% endcall %}
{% call row() %} {% call row() %}
{{ text_field('Free text message allowance')}} {{ text_field('Free text message allowance')}}
@@ -0,0 +1,22 @@
{% extends "withnav_template.html" %}
{% from "components/radios.html" import radios, branding_radios %}
{% from "components/page-footer.html" import page_footer %}
{% block service_page_title %}
Set branding and organisation
{% endblock %}
{% block maincolumn_content %}
<h1 class="heading-large">Set organisation type</h1>
<form method="post">
{{ radios(form.organisation_type) }}
{{ page_footer(
'Save',
back_link=url_for('.service_settings', service_id=current_service.id),
back_link_text='Back to settings'
) }}
</form>
</div>
{% endblock %}
+70 -2
View File
@@ -22,7 +22,7 @@ from tests.conftest import (
get_non_default_reply_to_email_address, get_non_default_reply_to_email_address,
get_default_letter_contact_block, get_default_letter_contact_block,
get_non_default_letter_contact_block, get_non_default_letter_contact_block,
SERVICE_ONE_ID SERVICE_ONE_ID,
) )
@@ -65,7 +65,7 @@ from tests.conftest import (
'Send letters Off Change', 'Send letters Off Change',
'Label Value Action', 'Label Value Action',
'Organisation type Central', 'Organisation type Central Change',
'Free text message allowance 250,000', 'Free text message allowance 250,000',
'Email branding GOV.UK Change', 'Email branding GOV.UK Change',
'Letter branding HM Government Change', 'Letter branding HM Government Change',
@@ -1362,6 +1362,74 @@ def test_should_set_branding_and_organisations(
) )
@pytest.mark.parametrize('method', ['get', 'post'])
def test_organisation_type_pages_are_platform_admin_only(
client_request,
method,
):
getattr(client_request, method)(
'main.set_organisation_type',
service_id=SERVICE_ONE_ID,
_expected_status=403,
_test_page_title=False,
)
def test_should_show_page_to_set_organisation_type(
logged_in_platform_admin_client,
):
response = logged_in_platform_admin_client.get(url_for(
'main.set_organisation_type',
service_id=SERVICE_ONE_ID
))
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
labels = page.select('label')
checked_radio_buttons = page.select('input[checked]')
assert len(checked_radio_buttons) == 1
assert checked_radio_buttons[0]['value'] == 'central'
assert len(labels) == 3
for index, expected in enumerate((
'Central government',
'Local government',
'NHS',
)):
assert normalize_spaces(labels[index].text) == expected
@pytest.mark.parametrize('organisation_type', [
'central',
'local',
'nhs',
pytest.mark.xfail('private sector'),
])
def test_should_set_organisaton_type(
logged_in_platform_admin_client,
mock_update_service,
organisation_type,
):
response = logged_in_platform_admin_client.post(
url_for(
'main.set_organisation_type',
service_id=SERVICE_ONE_ID,
),
data={
'organisation_type': organisation_type,
'organisation': 'organisation-id'
},
)
assert response.status_code == 302
assert response.location == url_for('main.service_settings', service_id=SERVICE_ONE_ID, _external=True)
mock_update_service.assert_called_once_with(
SERVICE_ONE_ID,
organisation_type=organisation_type,
)
def test_switch_service_enable_letters( def test_switch_service_enable_letters(
logged_in_platform_admin_client, logged_in_platform_admin_client,
service_one, service_one,