Merge pull request #2311 from alphagov/show-postage-class

Add letter class row to settings page, visible to platform admin only
This commit is contained in:
Katie Smith
2018-09-20 09:52:24 +01:00
committed by GitHub
9 changed files with 120 additions and 0 deletions

View File

@@ -684,6 +684,17 @@ class ServiceSwitchLettersForm(StripWhitespaceForm):
)
class ServicePostageForm(StripWhitespaceForm):
postage = RadioField(
'Choose your postage',
choices=[
('first', 'First class only'),
('second', 'Second class only'),
],
)
class BrandingStyle(RadioField):
def post_validate(self, form, validation_stopped):

View File

@@ -43,6 +43,7 @@ from app.main.forms import (
ServiceEditInboundNumberForm,
ServiceInboundNumberForm,
ServiceLetterContactBlockForm,
ServicePostageForm,
ServicePreviewBranding,
ServiceReplyToEmailForm,
ServiceSetBranding,
@@ -649,6 +650,19 @@ def service_set_letters(service_id):
)
@main.route("/services/<service_id>/service-settings/set-postage", methods=['GET', 'POST'])
@login_required
@user_is_platform_admin
def service_set_postage(service_id):
form = ServicePostageForm(postage=current_service.postage)
if form.validate_on_submit():
service_api_client.update_service(service_id, postage=form.postage.data)
return redirect(url_for(".service_settings", service_id=service_id))
return render_template('views/service-settings/set-postage.html', form=form)
@main.route("/services/<service_id>/service-settings/set-auth-type", methods=['GET'])
@login_required
@user_has_permissions('manage_service')

View File

@@ -230,6 +230,7 @@ class HeaderNavigation(Navigation):
'service_set_international_sms',
'service_set_letter_contact_block',
'service_set_letters',
'service_set_postage',
'service_set_reply_to_email',
'service_set_sms',
'service_set_sms_prefix',
@@ -352,6 +353,7 @@ class MainNavigation(Navigation):
'service_set_international_sms',
'service_set_letter_contact_block',
'service_set_letters',
'service_set_postage',
'service_set_reply_to_email',
'service_set_sms',
'service_set_sms_prefix',
@@ -677,6 +679,7 @@ class CaseworkNavigation(Navigation):
'service_set_international_sms',
'service_set_letter_contact_block',
'service_set_letters',
'service_set_postage',
'service_set_reply_to_email',
'service_set_sms',
'service_set_sms_prefix',
@@ -905,6 +908,7 @@ class OrgNavigation(Navigation):
'service_set_international_sms',
'service_set_letter_contact_block',
'service_set_letters',
'service_set_postage',
'service_set_reply_to_email',
'service_set_sms',
'service_set_sms_prefix',

View File

@@ -280,6 +280,7 @@ class Service(dict):
'name',
'organisation_type',
'permissions',
'postage',
'prefix_sms',
'research_mode',
'service_callback_api',

View File

@@ -88,6 +88,7 @@ class ServiceAPIClient(NotifyAdminAPIClient):
'free_sms_fragment_limit',
'prefix_sms',
'contact_link',
'postage',
}
if disallowed_attributes:
raise TypeError('Not allowed to update service attributes: {}'.format(

View File

@@ -235,6 +235,21 @@
)}}
{% endcall %}
{% if current_user.platform_admin %}
{% call row() %}
{{ text_field('Postage') }}
{% set postage = {'first': 'First class only', 'second': 'Second class only'} %}
{{ text_field(postage[current_service.postage]) }}
{{ edit_field(
'Change',
url_for('.service_set_postage',
service_id=current_service.id),
permissions=['manage_service']
)
}}
{% endcall %}
{% endif %}
{% endcall %}
</div>

View File

@@ -0,0 +1,39 @@
{% extends "withnav_template.html" %}
{% from "components/radios.html" import radios %}
{% from "components/page-footer.html" import page_footer %}
{% block service_page_title %}
Postage
{% endblock %}
{% block maincolumn_content %}
<div class="grid-row">
<div class="column-five-sixths">
<h1 class="heading-large">Postage</h1>
<p>You can send letters by first or second class post.</p>
<p>
See a list of <a href="{{ url_for('.pricing', _anchor='letters') }}">postage prices</a>.
</p>
<h2 class="heading-medium">Delivery times</h2>
<p>
Letters sent before 5:30pm are dispatched the next working day (Monday to Friday).
</p>
<p>
First class letters are delivered one day after theyre dispatched. Second class letters are delivered 2 days after theyre dispatched.
</p>
<p>
Royal Mail delivers from Monday to Saturday, excluding bank holidays.
</p>
<form method="post">
{{ radios(form.postage) }}
{{ page_footer(
'Save',
back_link=url_for('.service_settings', service_id=current_service.id),
back_link_text='Back to settings'
) }}
</form>
</div>
</div>
{% endblock %}

View File

@@ -146,6 +146,7 @@ def service_json(
organisation_type='central',
prefix_sms=True,
contact_link=None,
postage='second',
):
if users is None:
users = []
@@ -174,6 +175,7 @@ def service_json(
'inbound_api': inbound_api,
'service_callback_api': service_callback_api,
'prefix_sms': prefix_sms,
'postage': postage,
}

View File

@@ -89,6 +89,7 @@ def mock_get_service_settings_page_common(
'Label Value Action',
'Send letters Off Change',
'Postage Second class only Change',
'Label Value Action',
'Organisation Org 1 Change',
@@ -1849,6 +1850,38 @@ def test_set_letter_branding_saves(
mock_update_service.assert_called_once_with(service_one['id'], dvla_organisation='500')
def test_set_postage_platform_admin_only(
logged_in_client,
service_one,
):
response = logged_in_client.get(url_for('main.service_set_postage', service_id=SERVICE_ONE_ID))
assert response.status_code == 403
def test_set_postage_prepopulates(
logged_in_platform_admin_client,
service_one,
):
response = logged_in_platform_admin_client.get(url_for('main.service_set_postage', service_id=SERVICE_ONE_ID))
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert page.select('input[checked]')[0]['value'] == 'second'
def test_set_postage_saves(
logged_in_platform_admin_client,
service_one,
mock_update_service,
):
response = logged_in_platform_admin_client.post(
url_for('main.service_set_postage', service_id=SERVICE_ONE_ID),
data={'postage': 'first'}
)
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, postage='first')
@pytest.mark.parametrize('current_branding, expected_values, expected_labels', [
(None, [
'None', '1', '2', '3', '4', '5',