Skip to content

Commit 69a93c9

Browse files
committed
Check nomcom of nominations and that email is a nominee
See ietf-tools#930 - Legacy-Id: 5184
1 parent 7e83064 commit 69a93c9

2 files changed

Lines changed: 49 additions & 8 deletions

File tree

ietf/nomcom/forms.py

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ def get_group_or_404(year):
3131
nomcom__isnull=False)
3232

3333

34+
def get_list(string):
35+
return map(unicode.strip, string.replace('\r\n', '').split(','))
36+
37+
3438
class BaseNomcomForm(object):
3539
def __unicode__(self):
3640
return self.as_div()
@@ -82,8 +86,7 @@ def parse_params(self, *args, **kwargs):
8286
self.form.base_fields['members'].initial = ',\r\n'.join([role.email.address for role in members])
8387

8488
def process_preview(self, request, form, context):
85-
emails = form.cleaned_data['members'].replace('\r\n', '')
86-
members_email = map(unicode.strip, emails.split(','))
89+
members_email = get_list(form.cleaned_data['members'])
8790

8891
members_info = []
8992
emails_not_found = []
@@ -197,6 +200,29 @@ def __init__(self, *args, **kwargs):
197200
self.nomcom = kwargs.pop('nomcom', None)
198201
super(MergeForm, self).__init__(*args, **kwargs)
199202

203+
def clean_primary_email(self):
204+
email = self.cleaned_data['primary_email']
205+
nominees = Nominee.objects.filter(email__address=email,
206+
nomine_position__nomcom=self.nomcom)
207+
if not nominees:
208+
msg = "Does not exist a nomiee with this email"
209+
self._errors["primary_email"] = self.error_class([msg])
210+
211+
return email
212+
213+
def clean_secondary_emails(self):
214+
data = self.cleaned_data['secondary_emails']
215+
emails = get_list(data)
216+
for email in emails:
217+
nominees = Nominee.objects.filter(email__address=email,
218+
nomine_position__nomcom=self.nomcom)
219+
if not nominees:
220+
msg = "Does not exist a nomiee with email %s" % email
221+
self._errors["primary_email"] = self.error_class([msg])
222+
break
223+
224+
return data
225+
200226
def clean(self):
201227
primary_email = self.cleaned_data.get("primary_email")
202228
secondary_emails = self.cleaned_data.get("secondary_emails")
@@ -208,11 +234,12 @@ def clean(self):
208234

209235
def save(self):
210236
primary_email = self.cleaned_data.get("primary_email")
211-
secondary_emails = self.cleaned_data.get("secondary_emails").replace('\r\n', '')
212-
secondary_emails = map(unicode.strip, secondary_emails.split(','))
237+
secondary_emails = get_list(self.cleaned_data.get("secondary_emails"))
213238

214-
primary_nominee = Nominee.objects.get(email__address=primary_email)
215-
secondary_nominees = Nominee.objects.filter(email__address__in=secondary_emails)
239+
primary_nominee = Nominee.objects.get(email__address=primary_email,
240+
nomine_position__nomcom=self.nomcom)
241+
secondary_nominees = Nominee.objects.filter(email__address__in=secondary_emails,
242+
nomine_position__nomcom=self.nomcom)
216243
for nominee in secondary_nominees:
217244
# move nominations
218245
nominee.nomination_set.all().update(nominee=primary_nominee)
@@ -331,7 +358,8 @@ def save(self, commit=True):
331358
to_email = email.address
332359
context = {'nominee': email.person.name,
333360
'position': position}
334-
path = '%s%d/%s' % (nomcom_template_path, position.id, QUESTIONNAIRE_TEMPLATE)
361+
path = '%s%d/%s' % (nomcom_template_path,
362+
position.id, QUESTIONNAIRE_TEMPLATE)
335363
send_mail(None, to_email, from_email, subject, path, context)
336364

337365
# send emails to nomcom chair
@@ -351,7 +379,8 @@ def save(self, commit=True):
351379

352380
class Meta:
353381
model = Nomination
354-
fields = ('position', 'nominator_email', 'candidate_name', 'candidate_email', 'candidate_phone')
382+
fields = ('position', 'nominator_email', 'candidate_name',
383+
'candidate_email', 'candidate_phone')
355384

356385
class Media:
357386
js = ("/js/jquery-1.5.1.min.js",

ietf/nomcom/tests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ def test_private_merge_view(self):
112112
self.assertEqual(response.status_code, 200)
113113
self.assertContains(response, "info-message-error")
114114

115+
test_data = {"primary_email": "unknown@example.com",
116+
"secondary_emails": "nominee@example.com"}
117+
response = self.client.post(self.private_merge_url, test_data)
118+
self.assertEqual(response.status_code, 200)
119+
self.assertContains(response, "info-message-error")
120+
121+
test_data = {"primary_email": "nominee@example.com",
122+
"secondary_emails": "unknown@example.com"}
123+
response = self.client.post(self.private_merge_url, test_data)
124+
self.assertEqual(response.status_code, 200)
125+
self.assertContains(response, "info-message-error")
126+
115127
test_data = {"secondary_emails": """nominee2@example.com,
116128
nominee3@example.com,
117129
nominee4@example.com""",

0 commit comments

Comments
 (0)