Add form validation for max service and org name

There was a recent error in the logs because a service tried to change
its name to one exceeding 255 characters (which is a limit on the
database field). We can easily catch these errors on the form, so that
the user doesn't see an error page.
This commit is contained in:
Katie Smith
2020-11-30 17:08:40 +00:00
parent 4e96f82c67
commit 57189f57e4
4 changed files with 45 additions and 28 deletions

View File

@@ -1106,7 +1106,8 @@ class RenameServiceForm(StripWhitespaceForm):
u'Service name',
validators=[
DataRequired(message='Cannot be empty'),
MustContainAlphanumericCharacters()
MustContainAlphanumericCharacters(),
Length(max=255, message='Service name must be 255 characters or fewer')
])
@@ -1115,7 +1116,8 @@ class RenameOrganisationForm(StripWhitespaceForm):
u'Organisation name',
validators=[
DataRequired(message='Cannot be empty'),
MustContainAlphanumericCharacters()
MustContainAlphanumericCharacters(),
Length(max=255, message='Organisation name must be 255 characters or fewer')
])
@@ -1223,7 +1225,8 @@ class CreateServiceForm(StripWhitespaceForm):
"Whats your service called?",
validators=[
DataRequired(message='Cannot be empty'),
MustContainAlphanumericCharacters()
MustContainAlphanumericCharacters(),
Length(max=255, message='Service name must be 255 characters or fewer')
])
organisation_type = OrganisationTypeField('Who runs this service?')