mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 02:42:26 -05:00
Update the service name validation in the ServiceNameForm and AddServiceForm to check the email_safe version
of the name against a list of all service email_from fields. Update find_all_service_names to find_all_service_email_from, which returns the email_from of all services.
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
import re
|
||||
from flask_wtf import Form
|
||||
|
||||
from utils.recipients import (
|
||||
validate_phone_number,
|
||||
InvalidPhoneError
|
||||
)
|
||||
from wtforms import (
|
||||
StringField,
|
||||
PasswordField,
|
||||
ValidationError,
|
||||
TextAreaField,
|
||||
FileField,
|
||||
RadioField,
|
||||
BooleanField,
|
||||
HiddenField
|
||||
)
|
||||
@@ -16,12 +17,6 @@ from wtforms.validators import (DataRequired, Email, Length, Regexp)
|
||||
|
||||
from app.main.validators import (Blacklist, CsvFileValidator, ValidEmailDomainRegex)
|
||||
|
||||
from utils.recipients import (
|
||||
validate_phone_number,
|
||||
format_phone_number,
|
||||
InvalidPhoneError
|
||||
)
|
||||
|
||||
|
||||
def email_address(label='Email address'):
|
||||
return EmailField(label, validators=[
|
||||
@@ -159,7 +154,9 @@ class AddServiceForm(Form):
|
||||
)
|
||||
|
||||
def validate_name(self, a):
|
||||
if a.data.lower() in self._names_func():
|
||||
from app.utils import email_safe
|
||||
# make sure the email_from will be unique to all services
|
||||
if email_safe(a.data) in self._names_func():
|
||||
raise ValidationError('This service name is already in use')
|
||||
|
||||
|
||||
@@ -180,7 +177,9 @@ class ServiceNameForm(Form):
|
||||
])
|
||||
|
||||
def validate_name(self, a):
|
||||
if a.data.lower() in self._names_func():
|
||||
from app.utils import email_safe
|
||||
# make sure the email_from will be unique to all services
|
||||
if email_safe(a.data) in self._names_func():
|
||||
raise ValidationError('This service name is already in use')
|
||||
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ from app import (
|
||||
user_api_client,
|
||||
service_api_client
|
||||
)
|
||||
from app.utils import email_safe
|
||||
|
||||
|
||||
@main.route("/add-service", methods=['GET', 'POST'])
|
||||
@@ -31,12 +32,17 @@ def add_service():
|
||||
invite_api_client.accept_invite(service_id, invitation.id)
|
||||
return redirect(url_for('main.service_dashboard', service_id=service_id))
|
||||
|
||||
form = AddServiceForm(service_api_client.find_all_service_names_lower)
|
||||
form = AddServiceForm(service_api_client.find_all_service_email_from)
|
||||
heading = 'Which service do you want to set up notifications for?'
|
||||
if form.validate_on_submit():
|
||||
session['service_name'] = form.name.data
|
||||
service_id = service_api_client.create_service(
|
||||
session['service_name'], False, current_app.config['DEFAULT_SERVICE_LIMIT'], True, session['user_id'])
|
||||
email_from = email_safe(session['service_name'])
|
||||
service_id = service_api_client.create_service(service_name=session['service_name'],
|
||||
active=False,
|
||||
limit=current_app.config['DEFAULT_SERVICE_LIMIT'],
|
||||
restricted=True,
|
||||
user_id=session['user_id'],
|
||||
email_from=email_from)
|
||||
|
||||
return redirect(url_for('main.service_dashboard', service_id=service_id))
|
||||
else:
|
||||
|
||||
@@ -39,7 +39,7 @@ def service_settings(service_id):
|
||||
def service_name_change(service_id):
|
||||
service = service_api_client.get_service(service_id)['data']
|
||||
|
||||
form = ServiceNameForm(service_api_client.find_all_service_names_lower)
|
||||
form = ServiceNameForm(service_api_client.find_all_service_email_from)
|
||||
|
||||
if form.validate_on_submit():
|
||||
session['service_name_change'] = form.name.data
|
||||
|
||||
Reference in New Issue
Block a user