mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-05 02:41:14 -05:00
Set default branding for NHS services
The NHS is a special case because it’s not one organisation, but it does have one consistent brand. So anyone working for an NHS organisation should have their default branding set when they create a service, even if we know nothing about their specific organisation.
This commit is contained in:
@@ -12,7 +12,7 @@ def dao_get_email_branding_by_id(email_branding_id):
|
|||||||
|
|
||||||
|
|
||||||
def dao_get_email_branding_by_name(email_branding_name):
|
def dao_get_email_branding_by_name(email_branding_name):
|
||||||
return EmailBranding.query.filter_by(name=email_branding_name).one()
|
return EmailBranding.query.filter_by(name=email_branding_name).first()
|
||||||
|
|
||||||
|
|
||||||
@transactional
|
@transactional
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ def dao_get_letter_branding_by_id(letter_branding_id):
|
|||||||
return LetterBranding.query.filter(LetterBranding.id == letter_branding_id).one()
|
return LetterBranding.query.filter(LetterBranding.id == letter_branding_id).one()
|
||||||
|
|
||||||
|
|
||||||
|
def dao_get_letter_branding_by_name(letter_branding_name):
|
||||||
|
return LetterBranding.query.filter_by(name=letter_branding_name).first()
|
||||||
|
|
||||||
|
|
||||||
def dao_get_letter_branding_by_domain(domain):
|
def dao_get_letter_branding_by_domain(domain):
|
||||||
if not domain:
|
if not domain:
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ from app.dao.dao_utils import (
|
|||||||
transactional,
|
transactional,
|
||||||
version_class
|
version_class
|
||||||
)
|
)
|
||||||
|
from app.dao.email_branding_dao import dao_get_email_branding_by_name
|
||||||
|
from app.dao.letter_branding_dao import dao_get_letter_branding_by_name
|
||||||
from app.dao.organisation_dao import dao_get_organisation_by_email_address
|
from app.dao.organisation_dao import dao_get_organisation_by_email_address
|
||||||
from app.dao.service_sms_sender_dao import insert_service_sms_sender
|
from app.dao.service_sms_sender_dao import insert_service_sms_sender
|
||||||
from app.dao.service_user_dao import dao_get_service_user
|
from app.dao.service_user_dao import dao_get_service_user
|
||||||
@@ -38,7 +40,7 @@ from app.models import (
|
|||||||
SMS_TYPE,
|
SMS_TYPE,
|
||||||
LETTER_TYPE,
|
LETTER_TYPE,
|
||||||
)
|
)
|
||||||
from app.utils import get_london_midnight_in_utc, midnight_n_days_ago
|
from app.utils import email_address_is_nhs, get_london_midnight_in_utc, midnight_n_days_ago
|
||||||
|
|
||||||
DEFAULT_SERVICE_PERMISSIONS = [
|
DEFAULT_SERVICE_PERMISSIONS = [
|
||||||
SMS_TYPE,
|
SMS_TYPE,
|
||||||
@@ -201,6 +203,12 @@ def dao_create_service(
|
|||||||
if organisation.letter_branding and not service.letter_branding:
|
if organisation.letter_branding and not service.letter_branding:
|
||||||
service.letter_branding = organisation.letter_branding
|
service.letter_branding = organisation.letter_branding
|
||||||
|
|
||||||
|
if not organisation and (
|
||||||
|
service.organisation_type == 'nhs' or email_address_is_nhs(user.email_address)
|
||||||
|
):
|
||||||
|
service.email_branding = dao_get_email_branding_by_name('NHS')
|
||||||
|
service.letter_branding = dao_get_letter_branding_by_name('NHS')
|
||||||
|
|
||||||
db.session.add(service)
|
db.session.add(service)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -122,3 +122,9 @@ def escape_special_characters(string):
|
|||||||
r'\{}'.format(special_character)
|
r'\{}'.format(special_character)
|
||||||
)
|
)
|
||||||
return string
|
return string
|
||||||
|
|
||||||
|
|
||||||
|
def email_address_is_nhs(email_address):
|
||||||
|
return email_address.lower().endswith((
|
||||||
|
'@nhs.uk', '@nhs.net', '.nhs.uk', '.nhs.net',
|
||||||
|
))
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ from tests.app.db import (
|
|||||||
create_notification,
|
create_notification,
|
||||||
create_api_key,
|
create_api_key,
|
||||||
create_invited_user,
|
create_invited_user,
|
||||||
|
create_email_branding,
|
||||||
create_letter_branding,
|
create_letter_branding,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -115,12 +116,56 @@ def test_create_service_with_letter_branding(notify_db_session):
|
|||||||
organisation_type='central',
|
organisation_type='central',
|
||||||
created_by=user)
|
created_by=user)
|
||||||
dao_create_service(service, user, letter_branding=letter_branding)
|
dao_create_service(service, user, letter_branding=letter_branding)
|
||||||
assert Service.query.count() == 1
|
|
||||||
service_db = Service.query.one()
|
service_db = Service.query.one()
|
||||||
assert service_db.id == service.id
|
assert service_db.id == service.id
|
||||||
assert service.letter_branding == letter_branding
|
assert service.letter_branding == letter_branding
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('email_address, organisation_type', (
|
||||||
|
("test@example.gov.uk", 'nhs'),
|
||||||
|
("test@nhs.net", 'nhs'),
|
||||||
|
("test@nhs.net", 'local'),
|
||||||
|
("test@nhs.net", 'central'),
|
||||||
|
("test@nhs.uk", 'central'),
|
||||||
|
("test@example.nhs.uk", 'central'),
|
||||||
|
("TEST@NHS.UK", 'central'),
|
||||||
|
))
|
||||||
|
@pytest.mark.parametrize('branding_name_to_create, expected_branding', (
|
||||||
|
('NHS', True),
|
||||||
|
# Need to check that nothing breaks in environments that don’t have
|
||||||
|
# the NHS branding set up
|
||||||
|
('SHN', False),
|
||||||
|
))
|
||||||
|
def test_create_nhs_service_get_default_branding_based_on_email_address(
|
||||||
|
notify_db_session,
|
||||||
|
branding_name_to_create,
|
||||||
|
expected_branding,
|
||||||
|
email_address,
|
||||||
|
organisation_type,
|
||||||
|
):
|
||||||
|
user = create_user(email=email_address)
|
||||||
|
letter_branding = create_letter_branding(name=branding_name_to_create)
|
||||||
|
email_branding = create_email_branding(name=branding_name_to_create)
|
||||||
|
|
||||||
|
service = Service(
|
||||||
|
name="service_name",
|
||||||
|
email_from="email_from",
|
||||||
|
message_limit=1000,
|
||||||
|
restricted=False,
|
||||||
|
organisation_type=organisation_type,
|
||||||
|
created_by=user,
|
||||||
|
)
|
||||||
|
dao_create_service(service, user, letter_branding=letter_branding)
|
||||||
|
service_db = Service.query.one()
|
||||||
|
|
||||||
|
if expected_branding:
|
||||||
|
assert service_db.letter_branding == letter_branding
|
||||||
|
assert service_db.email_branding == email_branding
|
||||||
|
else:
|
||||||
|
assert service_db.letter_branding is None
|
||||||
|
assert service_db.email_branding is None
|
||||||
|
|
||||||
|
|
||||||
def test_cannot_create_two_services_with_same_name(notify_db_session):
|
def test_cannot_create_two_services_with_same_name(notify_db_session):
|
||||||
user = create_user()
|
user = create_user()
|
||||||
assert Service.query.count() == 0
|
assert Service.query.count() == 0
|
||||||
|
|||||||
Reference in New Issue
Block a user