Merge pull request #3268 from alphagov/proper-form-for-letter-branding

Parametrise branding request flow so it serves both email and letter branding
This commit is contained in:
Pea M. Tyczynska
2020-01-23 16:50:41 +00:00
committed by GitHub
10 changed files with 351 additions and 166 deletions

View File

@@ -1392,35 +1392,46 @@ class LinkOrganisationsForm(StripWhitespaceForm):
)
class BrandingOptionsEmail(StripWhitespaceForm):
class BrandingOptions(StripWhitespaceForm):
FALLBACK_OPTION_VALUE = 'something_else'
FALLBACK_OPTION = (FALLBACK_OPTION_VALUE, 'Something else')
options = RadioField('Choose your new email branding')
options = RadioField('Choose your new branding')
something_else = TextAreaField('Describe the branding you want')
def __init__(self, service, *args, **kwargs):
def __init__(self, service, *args, branding_type="email", **kwargs):
super().__init__(*args, **kwargs)
self.options.choices = tuple(self.get_available_choices(service))
self.options.choices = tuple(self.get_available_choices(service, branding_type))
self.options.label.text = 'Choose your new {} branding'.format(branding_type)
if self.something_else_is_only_option:
self.options.data = self.FALLBACK_OPTION_VALUE
@staticmethod
def get_available_choices(service):
def get_available_choices(service, branding_type):
if branding_type == "email":
organisation_branding_id = service.organisation.email_branding_id if service.organisation else None
service_branding_id = service.email_branding_id
service_branding_name = service.email_branding_name
elif branding_type == "letter":
organisation_branding_id = service.organisation.letter_branding_id if service.organisation else None
service_branding_id = service.letter_branding_id
service_branding_name = service.letter_branding_name
if (
service.organisation_type == Organisation.TYPE_CENTRAL and
service.organisation.email_branding_id is None and
service.email_branding_id is not None
service.organisation_type == Organisation.TYPE_CENTRAL
and organisation_branding_id is None
and service_branding_id is not None
and branding_type == "email"
):
yield ('govuk', 'GOV.UK')
if (
service.organisation_type == 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()
service.organisation_type == Organisation.TYPE_CENTRAL
and service.organisation
and organisation_branding_id is None
and service_branding_name.lower() != 'GOV.UK and {}'.format(service.organisation.name).lower()
and branding_type == "email"
):
yield ('govuk_and_org', 'GOV.UK and {}'.format(service.organisation.name))
@@ -1429,24 +1440,26 @@ class BrandingOptionsEmail(StripWhitespaceForm):
Organisation.TYPE_NHS_CENTRAL,
Organisation.TYPE_NHS_LOCAL,
Organisation.TYPE_NHS_GP,
} and service.email_branding_name != 'NHS'
}
and service_branding_name != 'NHS'
):
yield ('nhs', 'NHS')
if (
service.organisation and
service.organisation_type not in {
service.organisation
and service.organisation_type not in {
Organisation.TYPE_NHS_LOCAL,
Organisation.TYPE_NHS_CENTRAL,
Organisation.TYPE_NHS_GP,
} and (
service.email_branding_id is None or
service.email_branding_id != service.organisation.email_branding_id
}
and (
service_branding_id is None
or service_branding_id != organisation_branding_id
)
):
yield ('organisation', service.organisation.name)
yield BrandingOptionsEmail.FALLBACK_OPTION
yield BrandingOptions.FALLBACK_OPTION
@property
def something_else_is_only_option(self):
@@ -1454,8 +1467,8 @@ class BrandingOptionsEmail(StripWhitespaceForm):
def validate_something_else(self, field):
if (
self.something_else_is_only_option or
self.options.data == self.FALLBACK_OPTION_VALUE
self.something_else_is_only_option
or self.options.data == self.FALLBACK_OPTION_VALUE
) and not field.data:
raise ValidationError('Cannot be empty')

View File

@@ -30,7 +30,7 @@ from app import (
from app.extensions import zendesk_client
from app.main import main
from app.main.forms import (
BrandingOptionsEmail,
BrandingOptions,
ConfirmPasswordForm,
EstimateUsageForm,
FreeSMSAllowance,
@@ -1001,15 +1001,6 @@ def service_preview_letter_branding(service_id):
)
@main.route("/services/<uuid:service_id>/service-settings/request-letter-branding", methods=['GET', 'POST'])
@user_has_permissions('manage_service', 'manage_templates')
def request_letter_branding(service_id):
return render_template(
'views/service-settings/request-letter-branding.html',
from_template=request.args.get('from_template'),
)
@main.route("/services/<uuid:service_id>/service-settings/link-service-to-organisation", methods=['GET', 'POST'])
@user_is_platform_admin
def link_service_to_organisation(service_id):
@@ -1038,15 +1029,18 @@ def link_service_to_organisation(service_id):
)
@main.route("/services/<uuid:service_id>/branding-request/email", methods=['GET', 'POST'])
@main.route("/services/<uuid:service_id>/branding-request/<branding_type>", methods=['GET', 'POST'])
@user_has_permissions('manage_service')
def branding_request(service_id):
form = BrandingOptionsEmail(current_service)
def branding_request(service_id, branding_type):
form = BrandingOptions(current_service, branding_type=branding_type)
from_template = request.args.get('from_template')
if branding_type == "email":
branding_name = current_service.email_branding_name
elif branding_type == "letter":
branding_name = current_service.letter_branding_name
if form.validate_on_submit():
zendesk_client.create_ticket(
subject='Email branding request - {}'.format(current_service.name),
subject='{} branding request - {}'.format(branding_type.capitalize(), current_service.name),
message=(
'Organisation: {organisation}\n'
'Service: {service_name}\n'
@@ -1061,7 +1055,7 @@ def branding_request(service_id):
organisation=current_service.organisation.as_info_for_branding_request(current_user.email_domain),
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,
current_branding=branding_name,
branding_requested=dict(form.options.choices)[form.options.data],
new_paragraph='\n\n' if form.something_else.data else '',
detail=form.something_else.data or ''
@@ -1071,16 +1065,20 @@ def branding_request(service_id):
user_name=current_user.name,
tags=['notify_action', 'notify_branding'],
)
flash((
'Thanks for your branding request. Well get back to you '
'within one working day.'
), 'default')
return redirect(url_for('.service_settings', service_id=service_id))
return redirect(url_for(
'.view_template', service_id=current_service.id, template_id=from_template
) if from_template else url_for('.service_settings', service_id=current_service.id))
return render_template(
'views/service-settings/branding/email-options.html',
'views/service-settings/branding/branding-options.html',
form=form,
branding_type=branding_type,
branding_name=branding_name,
from_template=from_template
)

View File

@@ -436,6 +436,12 @@ class Service(JSONModel):
return 'GOV.UK'
return self.email_branding['name']
@cached_property
def letter_branding_name(self):
if self.letter_branding is None:
return 'no'
return self.letter_branding['name']
@property
def needs_to_change_email_branding(self):
return self.email_branding_id is None and self.organisation_type != Organisation.TYPE_CENTRAL

View File

@@ -238,7 +238,6 @@ class HeaderNavigation(Navigation):
'registration_continue',
'remove_user_from_organisation',
'remove_user_from_service',
'request_letter_branding',
'request_to_go_live',
'resend_email_link',
'resend_email_verification',
@@ -405,7 +404,6 @@ class MainNavigation(Navigation):
'branding_request',
'estimate_usage',
'link_service_to_organisation',
'request_letter_branding',
'request_to_go_live',
'service_add_email_reply_to',
'service_add_letter_contact',
@@ -805,7 +803,6 @@ class CaseworkNavigation(Navigation):
'registration_continue',
'remove_user_from_organisation',
'remove_user_from_service',
'request_letter_branding',
'request_to_go_live',
'resend_email_link',
'resend_email_verification',
@@ -1085,7 +1082,6 @@ class OrgNavigation(Navigation):
'register_from_org_invite',
'registration_continue',
'remove_user_from_service',
'request_letter_branding',
'request_to_go_live',
'resend_email_link',
'resend_email_verification',

View File

@@ -105,7 +105,7 @@
{{ text_field(current_service.email_branding_name) }}
{{ edit_field(
'Change',
url_for('.branding_request', service_id=current_service.id),
url_for('.branding_request', service_id=current_service.id, branding_type="email"),
permissions=['manage_service'],
)}}
{% endcall %}
@@ -241,7 +241,7 @@
{{ optional_text_field(current_service.letter_branding.name) }}
{{ edit_field(
'Change',
url_for('.request_letter_branding', service_id=current_service.id),
url_for('.branding_request', service_id=current_service.id, branding_type="letter"),
permissions=['manage_service']
)}}
{% endcall %}

View File

@@ -7,21 +7,21 @@
{% from "components/form.html" import form_wrapper %}
{% block service_page_title %}
Change email branding
Change {{ branding_type }} branding
{% endblock %}
{% block maincolumn_content %}
{{ page_header(
'Change email branding',
back_link=url_for('main.service_settings', service_id=current_service.id)
'Change {} branding'.format(branding_type),
back_link=url_for('.view_template', service_id=current_service.id, template_id=from_template) if from_template else url_for('.service_settings', service_id=current_service.id)
) }}
<p>
Your emails currently have {{ current_service.email_branding_name }} branding.
Your {{ branding_type }}s currently have {{ branding_name }} branding.
</p>
{% if current_service.needs_to_change_email_branding %}
{% if current_service.needs_to_change_email_branding and branding_type == "email" %}
<p>
You should be using your own branding instead. We can help you to set this up.
</p>

View File

@@ -1,39 +0,0 @@
{% extends "withnav_template.html" %}
{% from "components/radios.html" import radios %}
{% from "components/page-header.html" import page_header %}
{% from "components/page-footer.html" import page_footer %}
{% block service_page_title %}
Letter branding
{% endblock %}
{% block maincolumn_content %}
{{ page_header(
'Letter branding',
back_link=url_for('.view_template', service_id=current_service.id, template_id=from_template) if from_template else url_for('.service_settings', service_id=current_service.id)
) }}
<div class="grid-row">
<div class="column-three-quarters">
{% if current_service.letter_branding_id %}
<p>
Your letters have the {{ current_service.letter_branding.name }} logo.
</p>
<p>
<a href="{{ url_for('main.feedback', ticket_type='ask-question-give-feedback', body='letter-branding') }}">Contact us</a>
if you want to use a different logo.
</p>
{% else %}
<p>
Your letters do not have a logo.
</p>
<p>
<a href="{{ url_for('main.feedback', ticket_type='ask-question-give-feedback', body='letter-branding') }}">Contact us</a>
if you want to add your organisations logo.
</p>
{% endif %}
</div>
</div>
{% endblock %}

View File

@@ -51,7 +51,7 @@
<div class="column-whole template-container">
{% if current_user.has_permissions('manage_templates') and template.template_type == 'letter' %}
{% if not current_service.letter_branding_id %}
<a href="{{ url_for(".request_letter_branding", service_id=current_service.id, from_template=template.id) }}" class="edit-template-link-letter-branding">Add logo</a>
<a href="{{ url_for(".branding_request", service_id=current_service.id, branding_type="letter", from_template=template.id) }}" class="edit-template-link-letter-branding">Add logo</a>
{% endif %}
<a href="{{ url_for(".edit_template_postage", service_id=current_service.id, template_id=template.id) }}" class="edit-template-link-letter-postage">Change</a>
<a href="{{ url_for(".edit_service_template", service_id=current_service.id, template_id=template.id) }}" class="edit-template-link-letter-body">Edit</a>