mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-16 19:30:13 -04:00
Persist canonical domain in email branding
When saving an email branding it’s possible we might not enter the canonical domain for an organisation into the domain field. Because we’re going to use the canonical domain to look up the brandings this will cause a mismatch. Rather than validate this and show an error, let’s just save the correct thing instead. From the user’s perspective this means everything will just work (ie a user with a given email address will automatically get the right branding for their organisation).
This commit is contained in:
@@ -43,7 +43,7 @@ from app.main.validators import (
|
||||
ValidGovEmail,
|
||||
)
|
||||
from app.notify_client.models import permissions, roles
|
||||
from app.utils import guess_name_from_email_address
|
||||
from app.utils import AgreementInfo, guess_name_from_email_address
|
||||
|
||||
|
||||
def get_time_value_and_label(future_time):
|
||||
@@ -720,10 +720,18 @@ class ServicePreviewBranding(StripWhitespaceForm):
|
||||
branding_style = HiddenField('branding_style')
|
||||
|
||||
|
||||
class GovernmentDomainField(StringField):
|
||||
validators = [KnownGovernmentDomain()]
|
||||
|
||||
def post_validate(self, form, validation_stopped):
|
||||
if self.data and not self.errors:
|
||||
self.data = AgreementInfo(self.data).canonical_domain
|
||||
|
||||
|
||||
class ServiceUpdateEmailBranding(StripWhitespaceForm):
|
||||
name = StringField('Name of brand')
|
||||
text = StringField('Text')
|
||||
domain = StringField('Domain', validators=[KnownGovernmentDomain()])
|
||||
domain = GovernmentDomainField('Domain')
|
||||
colour = StringField(
|
||||
'Colour',
|
||||
validators=[
|
||||
|
||||
@@ -150,6 +150,49 @@ def test_cant_create_new_email_branding_with_unknown_domain(
|
||||
assert page.select_one('.error-message').text.strip() == (
|
||||
'Not a known government domain (you might need to update domains.yml)'
|
||||
)
|
||||
assert page.select_one('input[name=domain]')['value'] == (
|
||||
'example.gov.uk'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('posted_domain, persisted_domain', [
|
||||
('voa.gsi.gov.uk', 'voa.gov.uk'),
|
||||
('voa.gov.uk', 'voa.gov.uk'),
|
||||
('hmcts.net', 'hmcts.gov.uk'),
|
||||
])
|
||||
def test_persists_canonical_domain_when_adding_email_branding(
|
||||
client_request,
|
||||
mocker,
|
||||
fake_uuid,
|
||||
mock_create_email_branding,
|
||||
posted_domain,
|
||||
persisted_domain,
|
||||
):
|
||||
mocker.patch('app.main.views.email_branding.persist_logo')
|
||||
mocker.patch('app.main.views.email_branding.delete_temp_files_created_by')
|
||||
data = {
|
||||
'logo': None,
|
||||
'colour': '#ff0000',
|
||||
'text': 'new text',
|
||||
'name': 'new name',
|
||||
'domain': posted_domain,
|
||||
'brand_type': 'org',
|
||||
}
|
||||
client_request.login(platform_admin_user(fake_uuid))
|
||||
client_request.post(
|
||||
'.create_email_branding',
|
||||
content_type='multipart/form-data',
|
||||
_data=data,
|
||||
)
|
||||
|
||||
assert mock_create_email_branding.call_args == call(
|
||||
logo=data['logo'],
|
||||
name=data['name'],
|
||||
text=data['text'],
|
||||
colour=data['colour'],
|
||||
domain=persisted_domain,
|
||||
brand_type=data['brand_type']
|
||||
)
|
||||
|
||||
|
||||
def test_create_new_email_branding_when_branding_saved(
|
||||
|
||||
Reference in New Issue
Block a user