mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-19 05:53:51 -04:00
Validate non canonical domains
At the moment we transform what the user gives us, so if someone enters `digital.cabinet-office.gov.uk` it will automagically be saved as `cabinet-office.gov.uk`. This happens without the user knowing, and might have unintended consequences. So let’s tell them what the problem is, and let them decide what to do about it (which might be accepting the canonical domain, or adding a new organisation to domains.yml first).
This commit is contained in:
@@ -111,3 +111,25 @@ class KnownGovernmentDomain:
|
||||
def __call__(self, form, field):
|
||||
if field.data and AgreementInfo(field.data).owner is None:
|
||||
raise ValidationError(self.message)
|
||||
|
||||
|
||||
class CanonicalGovernmentDomain:
|
||||
|
||||
message = 'Not {} domain (use {} if appropriate)'
|
||||
|
||||
def __call__(self, form, field):
|
||||
|
||||
if not field.data:
|
||||
return
|
||||
|
||||
domain = AgreementInfo(field.data)
|
||||
|
||||
if not domain.is_canonical:
|
||||
raise ValidationError(
|
||||
self.message.format('a canonical', domain.canonical_domain)
|
||||
)
|
||||
|
||||
if field.data != domain.canonical_domain:
|
||||
raise ValidationError(
|
||||
self.message.format('an organisation-level', domain.canonical_domain)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user