mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-23 15:56:45 -04:00
Merge pull request #2048 from alphagov/email-colours-and-domain
Add banner_colour, single_id_color and domain to email_branding.
This commit is contained in:
@@ -30,7 +30,8 @@ from app.models import (
|
|||||||
NOTIFICATION_CREATED,
|
NOTIFICATION_CREATED,
|
||||||
NOTIFICATION_TECHNICAL_FAILURE,
|
NOTIFICATION_TECHNICAL_FAILURE,
|
||||||
NOTIFICATION_SENT,
|
NOTIFICATION_SENT,
|
||||||
NOTIFICATION_SENDING
|
NOTIFICATION_SENDING,
|
||||||
|
BRANDING_BOTH
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -198,8 +199,10 @@ def get_html_email_options(service):
|
|||||||
service.email_branding.logo
|
service.email_branding.logo
|
||||||
) if service.email_branding.logo else None
|
) if service.email_branding.logo else None
|
||||||
|
|
||||||
|
colour = _set_colour(service)
|
||||||
|
|
||||||
branding = {
|
branding = {
|
||||||
'brand_colour': service.email_branding.colour,
|
'brand_colour': colour,
|
||||||
'brand_logo': logo_url,
|
'brand_logo': logo_url,
|
||||||
'brand_name': service.email_branding.text,
|
'brand_name': service.email_branding.text,
|
||||||
}
|
}
|
||||||
@@ -209,6 +212,15 @@ def get_html_email_options(service):
|
|||||||
return dict(govuk_banner=govuk_banner, brand_banner=brand_banner, **branding)
|
return dict(govuk_banner=govuk_banner, brand_banner=brand_banner, **branding)
|
||||||
|
|
||||||
|
|
||||||
|
def _set_colour(service):
|
||||||
|
if service.branding in [BRANDING_BOTH, BRANDING_ORG]:
|
||||||
|
return service.email_branding.single_id_colour or service.email_branding.colour
|
||||||
|
elif service.branding == BRANDING_ORG_BANNER:
|
||||||
|
return service.email_branding.banner_colour or service.email_branding.colour
|
||||||
|
elif service.branding == BRANDING_GOVUK:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def technical_failure(notification):
|
def technical_failure(notification):
|
||||||
notification.status = NOTIFICATION_TECHNICAL_FAILURE
|
notification.status = NOTIFICATION_TECHNICAL_FAILURE
|
||||||
dao_update_notification(notification)
|
dao_update_notification(notification)
|
||||||
|
|||||||
@@ -4,9 +4,12 @@ post_create_email_branding_schema = {
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"colour": {"type": ["string", "null"]},
|
"colour": {"type": ["string", "null"]},
|
||||||
|
"banner_colour": {"type": ["string", "null"]},
|
||||||
|
"single_id_colour": {"type": ["string", "null"]},
|
||||||
"name": {"type": ["string", "null"]},
|
"name": {"type": ["string", "null"]},
|
||||||
"text": {"type": ["string", "null"]},
|
"text": {"type": ["string", "null"]},
|
||||||
"logo": {"type": ["string", "null"]}
|
"logo": {"type": ["string", "null"]},
|
||||||
|
"domain": {"type": ["string", "null"]},
|
||||||
},
|
},
|
||||||
"required": []
|
"required": []
|
||||||
}
|
}
|
||||||
@@ -17,9 +20,12 @@ post_update_email_branding_schema = {
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"colour": {"type": ["string", "null"]},
|
"colour": {"type": ["string", "null"]},
|
||||||
|
"banner_colour": {"type": ["string", "null"]},
|
||||||
|
"single_id_colour": {"type": ["string", "null"]},
|
||||||
"name": {"type": ["string", "null"]},
|
"name": {"type": ["string", "null"]},
|
||||||
"text": {"type": ["string", "null"]},
|
"text": {"type": ["string", "null"]},
|
||||||
"logo": {"type": ["string", "null"]}
|
"logo": {"type": ["string", "null"]},
|
||||||
|
"domain": {"type": ["string", "null"]},
|
||||||
},
|
},
|
||||||
"required": []
|
"required": []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,8 @@ def create_service(
|
|||||||
email_from=None,
|
email_from=None,
|
||||||
prefix_sms=True,
|
prefix_sms=True,
|
||||||
message_limit=1000,
|
message_limit=1000,
|
||||||
organisation_type='central'
|
organisation_type='central',
|
||||||
|
branding=None
|
||||||
):
|
):
|
||||||
service = Service(
|
service = Service(
|
||||||
name=service_name,
|
name=service_name,
|
||||||
@@ -86,7 +87,8 @@ def create_service(
|
|||||||
email_from=email_from if email_from else service_name.lower().replace(' ', '.'),
|
email_from=email_from if email_from else service_name.lower().replace(' ', '.'),
|
||||||
created_by=user or create_user(email='{}@digital.cabinet-office.gov.uk'.format(uuid.uuid4())),
|
created_by=user or create_user(email='{}@digital.cabinet-office.gov.uk'.format(uuid.uuid4())),
|
||||||
prefix_sms=prefix_sms,
|
prefix_sms=prefix_sms,
|
||||||
organisation_type=organisation_type
|
organisation_type=organisation_type,
|
||||||
|
branding=branding
|
||||||
)
|
)
|
||||||
|
|
||||||
dao_create_service(service, service.created_by, service_id, service_permissions=service_permissions)
|
dao_create_service(service, service.created_by, service_id, service_permissions=service_permissions)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ from app import mmg_client, firetext_client
|
|||||||
from app.dao import (provider_details_dao, notifications_dao)
|
from app.dao import (provider_details_dao, notifications_dao)
|
||||||
from app.dao.provider_details_dao import dao_switch_sms_provider_to_provider_with_identifier
|
from app.dao.provider_details_dao import dao_switch_sms_provider_to_provider_with_identifier
|
||||||
from app.delivery import send_to_providers
|
from app.delivery import send_to_providers
|
||||||
|
from app.delivery.send_to_providers import _set_colour
|
||||||
from app.exceptions import NotificationTechnicalFailureException
|
from app.exceptions import NotificationTechnicalFailureException
|
||||||
from app.models import (
|
from app.models import (
|
||||||
Notification,
|
Notification,
|
||||||
@@ -202,6 +203,7 @@ def test_send_sms_should_use_template_version_from_notification_not_latest(
|
|||||||
def test_should_call_send_sms_response_task_if_research_mode(
|
def test_should_call_send_sms_response_task_if_research_mode(
|
||||||
notify_db, sample_service, sample_notification, mocker, research_mode, key_type
|
notify_db, sample_service, sample_notification, mocker, research_mode, key_type
|
||||||
):
|
):
|
||||||
|
sample_service.branding = BRANDING_GOVUK
|
||||||
mocker.patch('app.mmg_client.send_sms')
|
mocker.patch('app.mmg_client.send_sms')
|
||||||
mocker.patch('app.delivery.send_to_providers.send_sms_response')
|
mocker.patch('app.delivery.send_to_providers.send_sms_response')
|
||||||
|
|
||||||
@@ -454,11 +456,13 @@ def test_get_html_email_renderer_with_branding_details_and_render_govuk_banner_o
|
|||||||
|
|
||||||
def test_get_html_email_renderer_prepends_logo_path(notify_api):
|
def test_get_html_email_renderer_prepends_logo_path(notify_api):
|
||||||
Service = namedtuple('Service', ['branding', 'email_branding'])
|
Service = namedtuple('Service', ['branding', 'email_branding'])
|
||||||
EmailBranding = namedtuple('EmailBranding', ['colour', 'name', 'logo', 'text'])
|
EmailBranding = namedtuple('EmailBranding', ['colour', 'name', 'logo', 'text', 'banner_colour', 'single_id_colour'])
|
||||||
|
|
||||||
email_branding = EmailBranding(colour='#000000', logo='justice-league.png',
|
email_branding = EmailBranding(colour='#000000', logo='justice-league.png',
|
||||||
name='Justice League',
|
name='Justice League',
|
||||||
text='League of Justice')
|
text='League of Justice',
|
||||||
|
banner_colour='#ABEBC6',
|
||||||
|
single_id_colour='#DB6849')
|
||||||
service = Service(branding=BRANDING_ORG, email_branding=email_branding)
|
service = Service(branding=BRANDING_ORG, email_branding=email_branding)
|
||||||
|
|
||||||
renderer = send_to_providers.get_html_email_options(service)
|
renderer = send_to_providers.get_html_email_options(service)
|
||||||
@@ -468,10 +472,12 @@ def test_get_html_email_renderer_prepends_logo_path(notify_api):
|
|||||||
|
|
||||||
def test_get_html_email_renderer_handles_email_branding_without_logo(notify_api):
|
def test_get_html_email_renderer_handles_email_branding_without_logo(notify_api):
|
||||||
Service = namedtuple('Service', ['branding', 'email_branding'])
|
Service = namedtuple('Service', ['branding', 'email_branding'])
|
||||||
EmailBranding = namedtuple('EmailBranding', ['colour', 'name', 'logo', 'text'])
|
EmailBranding = namedtuple('EmailBranding', ['colour', 'name', 'logo', 'text', 'banner_colour', 'single_id_colour'])
|
||||||
|
|
||||||
email_branding = EmailBranding(colour='#000000', logo=None, name='Justice League', text='League of Justice')
|
email_branding = EmailBranding(colour='#000000', logo=None, name='Justice League', text='League of Justice',
|
||||||
service = Service(branding=BRANDING_ORG, email_branding=email_branding)
|
banner_colour='#ABEBC6',
|
||||||
|
single_id_colour='#DB6849')
|
||||||
|
service = Service(branding=BRANDING_ORG_BANNER, email_branding=email_branding)
|
||||||
|
|
||||||
renderer = send_to_providers.get_html_email_options(service)
|
renderer = send_to_providers.get_html_email_options(service)
|
||||||
|
|
||||||
@@ -746,3 +752,26 @@ def test_send_email_to_provider_should_format_email_address(sample_email_notific
|
|||||||
html_body=ANY,
|
html_body=ANY,
|
||||||
reply_to_address=ANY,
|
reply_to_address=ANY,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@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(notify_db_session, colour, banner_colour, single_id_colour, branding_type, expected_colour):
|
||||||
|
Service = namedtuple('Service', ['branding', 'email_branding'])
|
||||||
|
email_branding = EmailBranding(colour=colour,
|
||||||
|
logo='justice-league.png',
|
||||||
|
name='Justice League',
|
||||||
|
text='League of Justice',
|
||||||
|
banner_colour=banner_colour,
|
||||||
|
single_id_colour=single_id_colour)
|
||||||
|
service = Service(branding=branding_type, email_branding=email_branding)
|
||||||
|
|
||||||
|
colour = _set_colour(service)
|
||||||
|
assert colour == expected_colour
|
||||||
|
|||||||
@@ -45,7 +45,10 @@ def test_post_create_email_branding(admin_request, notify_db_session):
|
|||||||
data = {
|
data = {
|
||||||
'name': 'test email_branding',
|
'name': 'test email_branding',
|
||||||
'colour': '#0000ff',
|
'colour': '#0000ff',
|
||||||
'logo': '/images/test_x2.png'
|
'banner_colour': '#808080',
|
||||||
|
'single_id_colour': '#FF0000',
|
||||||
|
'logo': '/images/test_x2.png',
|
||||||
|
'domain': 'gov.uk'
|
||||||
}
|
}
|
||||||
response = admin_request.post(
|
response = admin_request.post(
|
||||||
'email_branding.create_email_branding',
|
'email_branding.create_email_branding',
|
||||||
@@ -54,8 +57,11 @@ def test_post_create_email_branding(admin_request, notify_db_session):
|
|||||||
)
|
)
|
||||||
assert data['name'] == response['data']['name']
|
assert data['name'] == response['data']['name']
|
||||||
assert data['colour'] == response['data']['colour']
|
assert data['colour'] == response['data']['colour']
|
||||||
|
assert data['banner_colour'] == response['data']['banner_colour']
|
||||||
|
assert data['single_id_colour'] == response['data']['single_id_colour']
|
||||||
assert data['logo'] == response['data']['logo']
|
assert data['logo'] == response['data']['logo']
|
||||||
assert data['name'] == response['data']['text']
|
assert data['name'] == response['data']['text']
|
||||||
|
assert data['domain'] == response['data']['domain']
|
||||||
|
|
||||||
|
|
||||||
def test_post_create_email_branding_without_logo_is_ok(admin_request, notify_db_session):
|
def test_post_create_email_branding_without_logo_is_ok(admin_request, notify_db_session):
|
||||||
@@ -142,6 +148,8 @@ def test_post_create_email_branding_with_text_as_none_and_name(admin_request, no
|
|||||||
@pytest.mark.parametrize('data_update', [
|
@pytest.mark.parametrize('data_update', [
|
||||||
({'name': 'test email_branding 1'}),
|
({'name': 'test email_branding 1'}),
|
||||||
({'logo': 'images/text_x3.png', 'colour': '#ffffff'}),
|
({'logo': 'images/text_x3.png', 'colour': '#ffffff'}),
|
||||||
|
({'logo': 'images/text_x3.png', 'banner_colour': '#ffffff', 'single_id_colour': '#808080'}),
|
||||||
|
({'logo': 'images/text_x3.png', 'banner_colour': '#ffffff', 'single_id_colour': '#808080', 'domain': 'gov.uk'}),
|
||||||
])
|
])
|
||||||
def test_post_update_email_branding_updates_field(admin_request, notify_db_session, data_update):
|
def test_post_update_email_branding_updates_field(admin_request, notify_db_session, data_update):
|
||||||
data = {
|
data = {
|
||||||
|
|||||||
Reference in New Issue
Block a user