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,

View File

@@ -83,6 +83,7 @@ class Organisation(JSONModel):
self.domains = []
self.organisation_type = None
self.request_to_go_live_notes = None
self.email_branding_id = None
def as_agreement_statement_for_go_live_request(self, fallback_domain):
if self.agreement_signed:

View File

@@ -102,7 +102,7 @@
{% call settings_row(if_has_permission='email') %}
{{ text_field('Email branding') }}
{{ text_field('Your branding<br> ({})'.format(current_service.email_branding_name)|safe if current_service.email_branding else current_service.email_branding_name) }}
{{ text_field(current_service.email_branding_name) }}
{{ edit_field(
'Change',
url_for('.branding_request', service_id=current_service.id),

View File

@@ -1,5 +1,5 @@
{% extends "withnav_template.html" %}
{% from "components/radios.html" import radio %}
{% from "components/radios.html" import radios %}
{% from "components/textbox.html" import textbox %}
{% from "components/page-header.html" import page_header %}
{% from "components/page-footer.html" import page_footer %}
@@ -17,26 +17,7 @@
) }}
{% call form_wrapper() %}
<fieldset class="form-group {% if form.options.errors %}form-group-error{% endif %} top-gutter">
<legend class="bottom-gutter-2-3">
Choose the branding youd like on your emails.
</legend>
{% if form.options.errors %}
<span class="error-message" data-module="track-error" data-error-type="Cant be empty" data-error-label="{{ form.options.name }}">
You need to choose an option
</span>
{% endif %}
<div class="grid-row">
{% for option in form.options %}
<div class="column-one-quarter">
<label for="{{ option.id }}">
<img src="{{ asset_url('images/branding-options/{}.png'.format(option.data)) }}" alt="" class="bordered-image bottom-gutter-1-3">
</label>
{{ radio(option) }}
</div>
{% endfor %}
</div>
</fieldset>
{{ radios(form.options) }}
<p class="form-group">
Well email you once your brandings ready to use, or if we need any
more information.