Don’t allow adding unknown domains to branding lookup

We should make sure we’re not putting typos in the branding list. We can
validate what gets entered here against our known list of public-sector
domains.
This commit is contained in:
Chris Hill-Scott
2018-09-03 11:06:30 +01:00
parent 47c9b71fa8
commit 80423dfb3f
3 changed files with 53 additions and 7 deletions

View File

@@ -11,7 +11,7 @@ from wtforms.validators import Email
from app import formatted_list
from app.main._blacklisted_passwords import blacklisted_passwords
from app.utils import Spreadsheet, is_gov_user
from app.utils import AgreementInfo, Spreadsheet, is_gov_user
class Blacklist:
@@ -102,3 +102,12 @@ class DoesNotStartWithDoubleZero:
def __call__(self, form, field):
if field.data and field.data.startswith("00"):
raise ValidationError(self.message)
class KnownGovernmentDomain:
message = 'Not a known government domain (you might need to update domains.yml)'
def __call__(self, form, field):
if field.data and AgreementInfo(field.data).owner is None:
raise ValidationError(self.message)