Skip to content

Commit b4d7dd1

Browse files
committed
Added ability to use the submission API with active secondary email addresses. Fixes issue ietf-tools#2639.
- Legacy-Id: 17383
1 parent af6ca37 commit b4d7dd1

3 files changed

Lines changed: 66 additions & 7 deletions

File tree

changelog

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
ietfdb (6.119.1) ietf; urgency=medium
2+
3+
**Py2/3 fixes, Change to use the "requests" lib instead of urlopen()**
4+
5+
* Py2/3 compatibility tweaks for pyflakes.
6+
7+
* Changed some cases of urlopen() to use requests.get()
8+
9+
* Python3 is more ticklish about comparing strings to None than Py2.
10+
Fixed an issue with this in generate_sort_key() for document searches.
11+
12+
* Fixed a Py2/3 issue in the pyflakes management command, and tweaked the
13+
verbose output format.
14+
15+
* Merged back production changes to two scripts indirectly called by
16+
/a/www/www6s/scripts/run-ietf-report, through
17+
/a/www/www6s/scripts/run-report.
18+
19+
* Changed the release script to not pick up other email addresses than
20+
those of contributors from the release notes.
21+
22+
-- Henrik Levkowetz <henrik@levkowetz.com> 03 Mar 2020 11:23:46 +0000
23+
24+
125
ietfdb (6.119.0) ietf; urgency=medium
226

327
**Improved email handling, and roundup of Py2/3 conversion issues**

ietf/submit/tests.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from ietf.message.models import Message
3636
from ietf.name.models import FormalLanguageName
3737
from ietf.person.models import Person
38-
from ietf.person.factories import UserFactory, PersonFactory
38+
from ietf.person.factories import UserFactory, PersonFactory, EmailFactory
3939
from ietf.submit.models import Submission, Preapproval
4040
from ietf.submit.mail import add_submission_email, process_response_email
4141
from ietf.utils.mail import outbox, empty_outbox, get_payload
@@ -1773,6 +1773,26 @@ def test_api_submit_ok(self):
17731773
expected = "Upload of %s OK, confirmation requests sent to:\n %s" % (name, author.formatted_email().replace('\n',''))
17741774
self.assertContains(r, expected, status_code=200)
17751775

1776+
def test_api_submit_secondary_email_active(self):
1777+
person = PersonFactory()
1778+
email = EmailFactory(person=person)
1779+
r, author, name = self.post_submission('00', author=person, email=email.address)
1780+
for expected in [
1781+
"Upload of %s OK, confirmation requests sent to:" % (name, ),
1782+
author.formatted_email().replace('\n',''),
1783+
]:
1784+
self.assertContains(r, expected, status_code=200)
1785+
1786+
def test_api_submit_secondary_email_inactive(self):
1787+
person = PersonFactory()
1788+
prim = person.email()
1789+
prim.primary = True
1790+
prim.save()
1791+
email = EmailFactory(person=person, active=False)
1792+
r, author, name = self.post_submission('00', author=person, email=email.address)
1793+
expected = "No such user: %s" % email.address
1794+
self.assertContains(r, expected, status_code=400)
1795+
17761796
def test_api_submit_no_user(self):
17771797
email='nonexistant.user@example.org'
17781798
r, author, name = self.post_submission('00', email=email)

ietf/submit/views.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright The IETF Trust 2011-2019, All Rights Reserved
1+
# Copyright The IETF Trust 2011-2020, All Rights Reserved
22
# -*- coding: utf-8 -*-
33

44

@@ -30,7 +30,7 @@
3030
from ietf.ietfauth.utils import has_role, role_required
3131
from ietf.mailtrigger.utils import gather_address_lists
3232
from ietf.message.models import Message, MessageAttachment
33-
from ietf.person.models import Person
33+
from ietf.person.models import Person, Email
3434
from ietf.submit.forms import ( SubmissionManualUploadForm, SubmissionAutoUploadForm, AuthorForm,
3535
SubmitterForm, EditSubmissionForm, PreapprovalForm, ReplacesForm, SubmissionEmailForm, MessageModelForm )
3636
from ietf.submit.mail import ( send_full_url, send_manual_post_request, add_submission_email, get_reply_to )
@@ -106,10 +106,25 @@ def err(code, text):
106106
username = form.cleaned_data['user']
107107
user = User.objects.filter(username=username)
108108
if user.count() == 0:
109-
return err(400, "No such user: %s" % username)
110-
if user.count() > 1:
109+
# See if a secondary login was being used
110+
email = Email.objects.filter(address=username, active=True)
111+
# The error messages don't talk about 'email', as the field we're
112+
# looking at is still the 'username' field.
113+
if email.count() == 0:
114+
return err(400, "No such user: %s" % username)
115+
elif email.count() > 1:
116+
return err(500, "Multiple matching accounts for %s" % username)
117+
email = email.first()
118+
if not hasattr(email, 'person'):
119+
return err(400, "No person matches %s" % username)
120+
person = email.person
121+
if not hasattr(person, 'user'):
122+
return err(400, "No user matches: %s" % username)
123+
user = person.user
124+
elif user.count() > 1:
111125
return err(500, "Multiple matching accounts for %s" % username)
112-
user = user.first()
126+
else:
127+
user = user.first()
113128
if not hasattr(user, 'person'):
114129
return err(400, "No person with username %s" % username)
115130

@@ -133,7 +148,7 @@ def err(code, text):
133148
if errors:
134149
raise ValidationError(errors)
135150

136-
if not user.username.lower() in [ a['email'].lower() for a in authors ]:
151+
if not username.lower() in [ a['email'].lower() for a in authors ]:
137152
raise ValidationError('Submitter %s is not one of the document authors' % user.username)
138153

139154
submission.submitter = user.person.formatted_email()

0 commit comments

Comments
 (0)