Only show relevant choices of email branding

Users who work in local government can’t have GOV.UK branding on their
emails. And only those working for Companies House (for example) can
request the Companies House branding.

This commit adds:
- new choices of email branding, which offer the name of the branding,
  rather than the style
- logic to filter this list to only the applicable options, based on
  what we know about the user, service and organisation

This is a change from the previous approach which put the onus on users
to figure out the style of branding they wanted, when we might already
know that a lot of the options weren’t available to them, or would be
inconsistent with the branding of other services in their organisation.
This commit is contained in:
Chris Hill-Scott
2019-09-12 13:45:35 +01:00
parent 29a0611e42
commit 6d0d10e8de
7 changed files with 235 additions and 89 deletions

View File

@@ -1357,25 +1357,55 @@ class LinkOrganisationsForm(StripWhitespaceForm):
)
branding_options = (
('govuk', 'GOV.UK only'),
('both', 'GOV.UK and logo'),
('org', 'Your logo'),
('org_banner', 'Your logo on a colour'),
)
branding_options_dict = dict(branding_options)
class BrandingOptionsEmail(StripWhitespaceForm):
options = RadioField(
'Branding options',
choices=branding_options,
'Choose your new email branding',
validators=[
DataRequired()
],
)
def __init__(self, service, *args, **kwargs):
super().__init__(*args, **kwargs)
self.options.choices = tuple(self.get_available_choices(service))
@staticmethod
def get_available_choices(service):
if (
service.organisation_type == 'central' and
service.organisation.email_branding_id is None and
service.email_branding_id is not None
):
yield ('govuk', 'GOV.UK')
if (
service.organisation_type == 'central' and
service.organisation and
service.organisation.email_branding_id is None and
service.email_branding_name.lower() != 'GOV.UK and {}'.format(service.organisation.name).lower()
):
yield ('govuk_and_org', 'GOV.UK and {}'.format(service.organisation.name))
if (
service.organisation_type in {'nhs_local', 'nhs_central', 'nhs_gp'} and
service.email_branding_name != 'NHS'
):
yield ('nhs', 'NHS')
if (
service.organisation and
service.organisation_type not in {'nhs_local', 'nhs_central', 'nhs_gp'} and
(
service.email_branding_id is None or
service.email_branding_id != service.organisation.email_branding_id
)
):
yield ('organisation', service.organisation.name)
yield ('something_else', 'Something else')
class ServiceDataRetentionForm(StripWhitespaceForm):

View File

@@ -52,7 +52,6 @@ from app.main.forms import (
SetEmailBranding,
SetLetterBranding,
SMSPrefixForm,
branding_options_dict,
)
from app.utils import (
DELIVERED_STATUSES,
@@ -1036,14 +1035,7 @@ def link_service_to_organisation(service_id):
@user_has_permissions('manage_service')
def branding_request(service_id):
branding_type = 'govuk'
if current_service.email_branding:
branding_type = current_service.email_branding['brand_type']
form = BrandingOptionsEmail(
options=branding_type
)
form = BrandingOptionsEmail(current_service)
if form.validate_on_submit():
zendesk_client.create_ticket(
@@ -1060,7 +1052,7 @@ def branding_request(service_id):
service_name=current_service.name,
dashboard_url=url_for('main.service_dashboard', service_id=current_service.id, _external=True),
current_branding=current_service.email_branding_name,
branding_requested=branding_options_dict[form.options.data],
branding_requested=dict(form.options.choices)[form.options.data],
),
ticket_type=zendesk_client.TYPE_QUESTION,
user_email=current_user.email_address,