Skip to content

Commit

Permalink
Make list name validation consistent with job runner
Browse files Browse the repository at this point in the history
  • Loading branch information
rsa33 committed Dec 3, 2023
1 parent aeb047b commit 82edcb9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions control/webapp/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from srcf import domains
from srcf.controllib import jobs
from srcf.controllib.utils import validate_list_name
from srcf.database import Domain

from . import inspect_services, utils
Expand Down Expand Up @@ -130,9 +131,12 @@ def create_mailing_list():
listname = request.form.get("listname", "").strip()
if not listname:
error = "Please enter a list name."
elif re.search(r"[^a-z0-9_-]", listname):
error = "List names can only contain letters, numbers, hyphens and underscores."
else:
try:
validate_list_name(listname)
except ValueError as ex:
error = ex.args[0]
if not error:
lists = inspect_services.lookup_mailinglists(mem.crsid)
if "{}-{}".format(mem.crsid, listname) in lists:
error = "This mailing list already exists."
Expand Down
8 changes: 6 additions & 2 deletions control/webapp/society.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from srcf import domains
from srcf.controllib import jobs
from srcf.controllib.utils import validate_list_name
from srcf.database import Domain

from . import inspect_services, utils
Expand Down Expand Up @@ -176,9 +177,12 @@ def create_mailing_list(society):
listname = request.form.get("listname", "").strip()
if not listname:
error = "Please enter a list name."
elif re.search(r"[^a-z0-9_-]", listname):
error = "List names can only contain letters, numbers, hyphens and underscores."
else:
try:
validate_list_name(listname)
except ValueError as ex:
error = ex.args[0]
if not error:
lists = inspect_services.lookup_mailinglists(society)
if "{}-{}".format(society, listname) in lists:
error = "This mailing list already exists."
Expand Down

0 comments on commit 82edcb9

Please sign in to comment.