mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-30 19:29:43 -04:00
Make whitespace stripping work for whitelists too
It’s a bit hacky, but it fixes a potential issue for users.
Code adapted from:
2c34f678ab
This commit is contained in:
@@ -4,6 +4,7 @@ import weakref
|
||||
|
||||
from flask_wtf import FlaskForm as Form
|
||||
from datetime import datetime, timedelta
|
||||
from itertools import chain
|
||||
|
||||
from notifications_utils.recipients import (
|
||||
validate_phone_number,
|
||||
@@ -174,6 +175,17 @@ class StripWhitespaceForm(Form):
|
||||
return bound
|
||||
|
||||
|
||||
class StripWhitespaceStringField(StringField):
|
||||
def __init__(self, label=None, **kwargs):
|
||||
kwargs['filters'] = tuple(chain(
|
||||
kwargs.get('filters', ()),
|
||||
(
|
||||
strip_whitespace,
|
||||
),
|
||||
))
|
||||
super(StringField, self).__init__(label, **kwargs)
|
||||
|
||||
|
||||
class LoginForm(StripWhitespaceForm):
|
||||
email_address = StringField('Email address', validators=[
|
||||
Length(min=5, max=255),
|
||||
@@ -641,6 +653,14 @@ class LetterBranding(StripWhitespaceForm):
|
||||
)
|
||||
|
||||
|
||||
class EmailFieldInWhitelist(EmailField, StripWhitespaceStringField):
|
||||
pass
|
||||
|
||||
|
||||
class InternationalPhoneNumberInWhitelist(InternationalPhoneNumber, StripWhitespaceStringField):
|
||||
pass
|
||||
|
||||
|
||||
class Whitelist(StripWhitespaceForm):
|
||||
|
||||
def populate(self, email_addresses, phone_numbers):
|
||||
@@ -652,7 +672,7 @@ class Whitelist(StripWhitespaceForm):
|
||||
form_field[index].data = value
|
||||
|
||||
email_addresses = FieldList(
|
||||
EmailField(
|
||||
EmailFieldInWhitelist(
|
||||
'',
|
||||
validators=[
|
||||
Optional(),
|
||||
@@ -666,7 +686,7 @@ class Whitelist(StripWhitespaceForm):
|
||||
)
|
||||
|
||||
phone_numbers = FieldList(
|
||||
InternationalPhoneNumber(
|
||||
InternationalPhoneNumberInWhitelist(
|
||||
'',
|
||||
validators=[
|
||||
Optional()
|
||||
|
||||
Reference in New Issue
Block a user