mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-11 10:28:41 -04:00
Add platform admin setting for letter branding
Does two main things: - defines what ‘brands’ we support, in terms of the ID that DVLA use - adds a form to choose which branding a service uses (currently platform admin only, like email branding) By doing this we will be able to (with some more work) preview and send letters with a variety of different branding. Story: https://www.pivotaltracker.com/story/show/143506905
This commit is contained in:
@@ -83,6 +83,11 @@ class Config(object):
|
|||||||
r"assembly\.wales",
|
r"assembly\.wales",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
LETTER_BRANDING = [
|
||||||
|
('001', 'HM Government'),
|
||||||
|
('500', 'Land Registry'),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class Development(Config):
|
class Development(Config):
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
|||||||
@@ -538,6 +538,20 @@ class ServiceBrandingOrg(Form):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class LetterBranding(Form):
|
||||||
|
|
||||||
|
def __init__(self, choices=[], *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.dvla_org_id.choices = choices
|
||||||
|
|
||||||
|
dvla_org_id = RadioField(
|
||||||
|
'Which logo should this service’s letter have?',
|
||||||
|
validators=[
|
||||||
|
DataRequired()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Whitelist(Form):
|
class Whitelist(Form):
|
||||||
|
|
||||||
def populate(self, email_addresses, phone_numbers):
|
def populate(self, email_addresses, phone_numbers):
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ from app.main.forms import (
|
|||||||
ServiceReplyToEmailFrom,
|
ServiceReplyToEmailFrom,
|
||||||
ServiceSmsSender,
|
ServiceSmsSender,
|
||||||
ServiceLetterContactBlock,
|
ServiceLetterContactBlock,
|
||||||
ServiceBrandingOrg
|
ServiceBrandingOrg,
|
||||||
|
LetterBranding,
|
||||||
)
|
)
|
||||||
from app import user_api_client, current_service, organisations_client
|
from app import user_api_client, current_service, organisations_client
|
||||||
|
|
||||||
@@ -41,7 +42,10 @@ def service_settings(service_id):
|
|||||||
organisation = None
|
organisation = None
|
||||||
return render_template(
|
return render_template(
|
||||||
'views/service-settings.html',
|
'views/service-settings.html',
|
||||||
organisation=organisation
|
organisation=organisation,
|
||||||
|
letter_branding=dict(
|
||||||
|
current_app.config['LETTER_BRANDING']
|
||||||
|
).get(current_service.get('dvla_org_id', '001'))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -314,6 +318,28 @@ def service_set_branding_and_org(service_id):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@main.route("/services/<service_id>/service-settings/set-letter-branding", methods=['GET', 'POST'])
|
||||||
|
@login_required
|
||||||
|
@user_has_permissions(admin_override=True)
|
||||||
|
def set_letter_branding(service_id):
|
||||||
|
|
||||||
|
form = LetterBranding(choices=current_app.config['LETTER_BRANDING'])
|
||||||
|
|
||||||
|
if form.validate_on_submit():
|
||||||
|
service_api_client.update_service(
|
||||||
|
service_id,
|
||||||
|
dvla_organisation=form.dvla_org_id.data
|
||||||
|
)
|
||||||
|
return redirect(url_for('.service_settings', service_id=service_id))
|
||||||
|
|
||||||
|
form.dvla_org_id.data = current_service.get('dvla_organisation', '001')
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
'views/service-settings/set-letter-branding.html',
|
||||||
|
form=form,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_branding_as_value_and_label(organisations):
|
def get_branding_as_value_and_label(organisations):
|
||||||
return [
|
return [
|
||||||
(organisation['id'], organisation['name'])
|
(organisation['id'], organisation['name'])
|
||||||
|
|||||||
@@ -91,7 +91,8 @@ class ServiceAPIClient(NotifyAdminAPIClient):
|
|||||||
'created_by',
|
'created_by',
|
||||||
'branding',
|
'branding',
|
||||||
'organisation',
|
'organisation',
|
||||||
'letter_contact_block'
|
'letter_contact_block',
|
||||||
|
'dvla_org_id',
|
||||||
}
|
}
|
||||||
if disallowed_attributes:
|
if disallowed_attributes:
|
||||||
raise TypeError('Not allowed to update service attributes: {}'.format(
|
raise TypeError('Not allowed to update service attributes: {}'.format(
|
||||||
|
|||||||
@@ -103,6 +103,11 @@
|
|||||||
{% endcall %}
|
{% endcall %}
|
||||||
{{ edit_field('Change', url_for('.service_set_branding_and_org', service_id=current_service.id)) }}
|
{{ edit_field('Change', url_for('.service_set_branding_and_org', service_id=current_service.id)) }}
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
|
{% call row() %}
|
||||||
|
{{ text_field('Letter branding')}}
|
||||||
|
{{ text_field(letter_branding) }}
|
||||||
|
{{ edit_field('Change', url_for('.set_letter_branding', service_id=current_service.id)) }}
|
||||||
|
{% endcall %}
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
{% 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 letter branding
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block maincolumn_content %}
|
||||||
|
|
||||||
|
<h1 class="heading-large">Set letter branding</h1>
|
||||||
|
<div class="grid-row">
|
||||||
|
<div class="column-three-quarters">
|
||||||
|
<form method="post">
|
||||||
|
{{ radios(form.dvla_org_id) }}
|
||||||
|
{{ page_footer(
|
||||||
|
'Save',
|
||||||
|
back_link=url_for('.service_settings', service_id=current_service.id),
|
||||||
|
back_link_text='Back to settings'
|
||||||
|
) }}
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
@@ -10,23 +10,45 @@ import app
|
|||||||
from app.utils import email_safe
|
from app.utils import email_safe
|
||||||
from tests import validate_route_permission, service_json
|
from tests import validate_route_permission, service_json
|
||||||
|
|
||||||
|
from tests.conftest import active_user_with_permissions, platform_admin_user
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('user, expected_rows', [
|
||||||
|
(active_user_with_permissions, [
|
||||||
|
'Label Value Action',
|
||||||
|
'Service name service one Change',
|
||||||
|
'Email reply to address None Change',
|
||||||
|
'Text message sender 40604 Change'
|
||||||
|
]),
|
||||||
|
(platform_admin_user, [
|
||||||
|
'Label Value Action',
|
||||||
|
'Service name service one Change',
|
||||||
|
'Email reply to address None Change',
|
||||||
|
'Text message sender 40604 Change',
|
||||||
|
'Label Value Action',
|
||||||
|
'Email branding GOV.UK Change',
|
||||||
|
'Letter branding HM Government Change',
|
||||||
|
]),
|
||||||
|
])
|
||||||
def test_should_show_overview(
|
def test_should_show_overview(
|
||||||
logged_in_client,
|
client,
|
||||||
|
mocker,
|
||||||
service_one,
|
service_one,
|
||||||
|
fake_uuid,
|
||||||
|
user,
|
||||||
|
expected_rows,
|
||||||
):
|
):
|
||||||
response = logged_in_client.get(url_for(
|
client.login(user(fake_uuid), mocker, service_one)
|
||||||
|
response = client.get(url_for(
|
||||||
'main.service_settings', service_id=service_one['id']
|
'main.service_settings', service_id=service_one['id']
|
||||||
))
|
))
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||||
assert page.find('h1').text == 'Settings'
|
assert page.find('h1').text == 'Settings'
|
||||||
for index, row in enumerate([
|
rows = page.find_all('tr')
|
||||||
'Service name service one Change',
|
assert len(rows) == len(expected_rows)
|
||||||
'Email reply to address None Change',
|
for index, row in enumerate(expected_rows):
|
||||||
'Text message sender 40604 Change'
|
assert row == " ".join(rows[index].text.split())
|
||||||
]):
|
|
||||||
assert row == " ".join(page.find_all('tr')[index + 1].text.split())
|
|
||||||
app.service_api_client.get_service.assert_called_with(service_one['id'])
|
app.service_api_client.get_service.assert_called_with(service_one['id'])
|
||||||
|
|
||||||
|
|
||||||
@@ -660,6 +682,46 @@ def test_set_letter_contact_block_has_max_10_lines(
|
|||||||
assert error_message == 'Contains 11 lines, maximum is 10'
|
assert error_message == 'Contains 11 lines, maximum is 10'
|
||||||
|
|
||||||
|
|
||||||
|
def test_set_letter_branding_platform_admin_only(
|
||||||
|
logged_in_client,
|
||||||
|
service_one,
|
||||||
|
):
|
||||||
|
response = logged_in_client.get(url_for('main.set_letter_branding', service_id=service_one['id']))
|
||||||
|
assert response.status_code == 403
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('current_dvla_org_id, expected_selected', [
|
||||||
|
(None, '001'),
|
||||||
|
('500', '500'),
|
||||||
|
])
|
||||||
|
def test_set_letter_branding_prepopulates(
|
||||||
|
logged_in_platform_admin_client,
|
||||||
|
service_one,
|
||||||
|
current_dvla_org_id,
|
||||||
|
expected_selected,
|
||||||
|
):
|
||||||
|
if current_dvla_org_id:
|
||||||
|
service_one['dvla_organisation'] = current_dvla_org_id
|
||||||
|
response = logged_in_platform_admin_client.get(url_for('main.set_letter_branding', 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'] == expected_selected
|
||||||
|
|
||||||
|
|
||||||
|
def test_set_letter_contact_block_saves(
|
||||||
|
logged_in_platform_admin_client,
|
||||||
|
service_one,
|
||||||
|
mock_update_service,
|
||||||
|
):
|
||||||
|
response = logged_in_platform_admin_client.post(
|
||||||
|
url_for('main.set_letter_branding', service_id=service_one['id']),
|
||||||
|
data={'dvla_org_id': '500'}
|
||||||
|
)
|
||||||
|
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'], dvla_organisation='500')
|
||||||
|
|
||||||
|
|
||||||
def test_should_show_branding(
|
def test_should_show_branding(
|
||||||
logged_in_platform_admin_client,
|
logged_in_platform_admin_client,
|
||||||
service_one,
|
service_one,
|
||||||
|
|||||||
Reference in New Issue
Block a user