mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-06 14:48:24 -04:00
Created a method to decide which colour to pass into the notifications-utils method to preview the template.
Removed the ServiceCreateEmailBranding form - it is identical to the other form.
This commit is contained in:
@@ -756,35 +756,6 @@ class ServiceUpdateEmailBranding(StripWhitespaceForm):
|
||||
file = FileField_wtf('Upload a PNG logo', validators=[FileAllowed(['png'], 'PNG Images only!')])
|
||||
|
||||
|
||||
class ServiceCreateEmailBranding(StripWhitespaceForm):
|
||||
|
||||
name = StringField('Name of brand')
|
||||
text = StringField('Text')
|
||||
domain = StringField('Domain')
|
||||
colour = StringField(
|
||||
'Colour',
|
||||
render_kw={'onchange': 'update_colour(this)'},
|
||||
validators=[
|
||||
Regexp(regex="^$|^#(?:[0-9a-fA-F]{3}){1,2}$", message='Must be a valid color hex code')
|
||||
]
|
||||
)
|
||||
banner_colour = StringField(
|
||||
'Banner colour',
|
||||
render_kw={'onchange': 'update_colour(this)'},
|
||||
validators=[
|
||||
Regexp(regex="^$|^#(?:[0-9a-fA-F]{3}){1,2}$", message='Must be a valid color hex code')
|
||||
]
|
||||
)
|
||||
single_id_colour = StringField(
|
||||
'Single identity colour',
|
||||
render_kw={'onchange': 'update_colour(this)'},
|
||||
validators=[
|
||||
Regexp(regex="^$|^#(?:[0-9a-fA-F]{3}){1,2}$", message='Must be a valid color hex code')
|
||||
]
|
||||
)
|
||||
file = FileField_wtf('Upload a PNG logo', validators=[FileAllowed(['png'], 'PNG Images only!')])
|
||||
|
||||
|
||||
class CreateOrUpdateOrganisation(StripWhitespaceForm):
|
||||
|
||||
name = StringField('Name', validators=[DataRequired()])
|
||||
|
||||
@@ -4,7 +4,6 @@ from flask_login import login_required
|
||||
from app import email_branding_client
|
||||
from app.main import main
|
||||
from app.main.forms import (
|
||||
ServiceCreateEmailBranding,
|
||||
ServiceSelectEmailBranding,
|
||||
ServiceUpdateEmailBranding,
|
||||
)
|
||||
@@ -109,7 +108,7 @@ def update_email_branding(branding_id, logo=None):
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
def create_email_branding(logo=None):
|
||||
form = ServiceCreateEmailBranding()
|
||||
form = ServiceUpdateEmailBranding()
|
||||
|
||||
if form.validate_on_submit():
|
||||
if form.file.data:
|
||||
|
||||
@@ -78,6 +78,13 @@ def design_content():
|
||||
return render_template('views/design-patterns-content-guidance.html')
|
||||
|
||||
|
||||
def _set_colour(branding_style, email_branding):
|
||||
if branding_style in ['both', 'org']:
|
||||
return email_branding['single_id_colour'] or email_branding['colour']
|
||||
elif branding_style == 'org_banner':
|
||||
return email_branding['banner_colour'] or email_branding['colour']
|
||||
|
||||
|
||||
@main.route('/_email')
|
||||
def email_template():
|
||||
branding_type = request.args.get('branding_type', 'govuk')
|
||||
@@ -91,8 +98,9 @@ def email_template():
|
||||
brand_banner = False
|
||||
else:
|
||||
email_branding = email_branding_client.get_email_branding(branding_style)['email_branding']
|
||||
colour = _set_colour(branding_type, email_branding)
|
||||
brand_name = email_branding['text']
|
||||
brand_colour = email_branding['colour']
|
||||
brand_colour = colour
|
||||
brand_logo = 'https://{}/{}'.format(get_cdn_domain(), email_branding['logo'])
|
||||
govuk_banner = branding_type in ['govuk', 'both']
|
||||
brand_banner = branding_type == 'org_banner'
|
||||
|
||||
@@ -4,6 +4,8 @@ import pytest
|
||||
from bs4 import BeautifulSoup
|
||||
from flask import url_for
|
||||
|
||||
from app.main.views.index import _set_colour
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"query_args, result", [
|
||||
@@ -86,7 +88,7 @@ def test_displays_org_branding_with_banner(client, mock_get_email_branding):
|
||||
|
||||
assert not page.find("a", attrs={"href": "https://www.gov.uk"})
|
||||
assert page.find("img", attrs={"src": re.compile("example.png")})
|
||||
assert page.select("body > table > tr > td[bgcolor='#f00']") # banner colour is set
|
||||
assert page.select("body > table > tr > td[bgcolor='#f11']") # banner colour is set
|
||||
assert page.select("body > table table > tr > td > span")[0]\
|
||||
.get_text().strip() == 'Organisation text' # brand text is set
|
||||
|
||||
@@ -104,5 +106,28 @@ def test_displays_org_branding_with_banner_without_brand_text(
|
||||
|
||||
assert not page.find("a", attrs={"href": "https://www.gov.uk"})
|
||||
assert page.find("img", attrs={"src": re.compile("example.png")})
|
||||
assert page.select("body > table > tr > td[bgcolor='#f00']") # banner colour is set
|
||||
assert page.select("body > table > tr > td[bgcolor='#f11']") # banner colour is set
|
||||
assert not page.select("body > table table > tr > td > span") == 0 # brand text is not set
|
||||
|
||||
|
||||
@pytest.mark.parametrize('colour, banner_colour, single_id_colour, branding_type, expected_colour', [
|
||||
('black', 'yellow', 'red', 'org', 'red'),
|
||||
('black', 'yellow', None, 'org', 'black'),
|
||||
('black', 'yellow', 'red', 'org_banner', 'yellow'),
|
||||
('black', None, 'red', 'org_banner', 'black'),
|
||||
('black', 'yellow', 'red', 'govuk', None),
|
||||
('black', 'yellow', 'red', 'both', 'red'),
|
||||
('black', 'yellow', None, 'both', 'black'),
|
||||
])
|
||||
def test_set_colour(colour, banner_colour, single_id_colour, branding_type, expected_colour):
|
||||
email_branding = {
|
||||
'logo': None,
|
||||
'colour': colour,
|
||||
'text': 'new text',
|
||||
'name': 'new name',
|
||||
'domain': 'sample.com',
|
||||
'banner_colour': banner_colour,
|
||||
'single_id_colour': single_id_colour,
|
||||
}
|
||||
colour = _set_colour(branding_type, email_branding)
|
||||
assert colour == expected_colour
|
||||
|
||||
@@ -2514,7 +2514,9 @@ def mock_get_email_branding_without_brand_text(mocker, fake_uuid):
|
||||
'name': 'Organisation name',
|
||||
'text': '',
|
||||
'id': fake_uuid,
|
||||
'colour': '#f00'
|
||||
'colour': '#f00',
|
||||
'banner_colour': '#f11',
|
||||
'single_id_colour': '#f22'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user