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:
Chris Hill-Scott
2018-09-03 11:14:37 +01:00
parent 80423dfb3f
commit 2e7ae91029
2 changed files with 53 additions and 2 deletions

View File

@@ -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=[