Skip to content

Commit a15d0ec

Browse files
committed
Prevent people from adding ietf list addresses to their personal accounts.
- Legacy-Id: 11218
1 parent caf3a4c commit a15d0ec

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

ietf/ietfauth/forms.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import re
22

33
from django import forms
4+
from django.conf import settings
5+
from django.core.exceptions import ValidationError
46
from django.forms import ModelForm
57
from django.db import models
68
from django.contrib.auth.models import User
@@ -64,6 +66,11 @@ def clean_new_email(self):
6466
existing = Email.objects.filter(address=email).first()
6567
if existing:
6668
raise forms.ValidationError("Email address '%s' is already assigned to account '%s' (%s)" % (existing, existing.person and existing.person.user, existing.person))
69+
70+
for pat in settings.EXLUDED_PERSONAL_EMAIL_REGEX_PATTERNS:
71+
if re.search(pat, email):
72+
raise ValidationError("This email address is not valid in a datatracker account")
73+
6774
return email
6875

6976

@@ -76,7 +83,7 @@ def __init__(self, role, *args, **kwargs):
7683
f = self.fields["email"]
7784
f.label = u"%s in %s" % (role.name, role.group.acronym.upper())
7885
f.help_text = u"Email to use for <i>%s</i> role in %s" % (role.name, role.group.name)
79-
f.queryset = f.queryset.filter(models.Q(person=role.person_id) | models.Q(role=role))
86+
f.queryset = f.queryset.filter(models.Q(person=role.person_id) | models.Q(role=role)).distinct()
8087
f.initial = role.email_id
8188
f.choices = [(e.pk, e.address if e.active else u"({})".format(e.address)) for e in f.queryset]
8289

ietf/secr/rolodex/forms.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django import forms
2+
from django.conf import settings
23
from django.contrib.auth.models import User
3-
from django.core.exceptions import ObjectDoesNotExist
4+
from django.core.exceptions import ObjectDoesNotExist, ValidationError
45
from django.core.validators import validate_email
56

67
from ietf.person.models import Email, Person
@@ -87,6 +88,10 @@ def clean_address(self):
8788
if address:
8889
validate_email(address)
8990

91+
for pat in settings.EXLUDED_PERSONAL_EMAIL_REGEX_PATTERNS:
92+
if re.search(pat, address):
93+
raise ValidationError("This email address is not valid in a datatracker account")
94+
9095
return address
9196

9297
class NewPersonForm(forms.ModelForm):

ietf/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,10 @@ def skip_unreadable_post(record):
608608
TRAC_WIKI_DIR = "/a/www/www6s/trac"
609609
TRAC_SVN_DIR = "/a/svn/group"
610610

611+
# Email addresses people attempt to set for their account will be checked
612+
# against the following list of regex expressions with re.search(pat, addr):
613+
EXLUDED_PERSONAL_EMAIL_REGEX_PATTERNS = ["@ietf.org$"]
614+
611615
# Put the production SECRET_KEY in settings_local.py, and also any other
612616
# sensitive or site-specific changes. DO NOT commit settings_local.py to svn.
613617
from settings_local import * # pyflakes:ignore

0 commit comments

Comments
 (0)