From b4d7dd131a39967422ac725e165647d822625b4e Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Wed, 4 Mar 2020 18:05:56 +0000 Subject: [PATCH] Added ability to use the submission API with active secondary email addresses. Fixes issue #2639. - Legacy-Id: 17383 --- changelog | 24 ++++++++++++++++++++++++ ietf/submit/tests.py | 22 +++++++++++++++++++++- ietf/submit/views.py | 27 +++++++++++++++++++++------ 3 files changed, 66 insertions(+), 7 deletions(-) diff --git a/changelog b/changelog index a0b2b2395..2545242be 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,27 @@ +ietfdb (6.119.1) ietf; urgency=medium + + **Py2/3 fixes, Change to use the "requests" lib instead of urlopen()** + + * Py2/3 compatibility tweaks for pyflakes. + + * Changed some cases of urlopen() to use requests.get() + + * Python3 is more ticklish about comparing strings to None than Py2. + Fixed an issue with this in generate_sort_key() for document searches. + + * Fixed a Py2/3 issue in the pyflakes management command, and tweaked the + verbose output format. + + * Merged back production changes to two scripts indirectly called by + /a/www/www6s/scripts/run-ietf-report, through + /a/www/www6s/scripts/run-report. + + * Changed the release script to not pick up other email addresses than + those of contributors from the release notes. + + -- Henrik Levkowetz 03 Mar 2020 11:23:46 +0000 + + ietfdb (6.119.0) ietf; urgency=medium **Improved email handling, and roundup of Py2/3 conversion issues** diff --git a/ietf/submit/tests.py b/ietf/submit/tests.py index 7cc5d34d5..cbfde5e3f 100644 --- a/ietf/submit/tests.py +++ b/ietf/submit/tests.py @@ -35,7 +35,7 @@ from ietf.meeting.factories import MeetingFactory from ietf.message.models import Message from ietf.name.models import FormalLanguageName from ietf.person.models import Person -from ietf.person.factories import UserFactory, PersonFactory +from ietf.person.factories import UserFactory, PersonFactory, EmailFactory from ietf.submit.models import Submission, Preapproval from ietf.submit.mail import add_submission_email, process_response_email from ietf.utils.mail import outbox, empty_outbox, get_payload @@ -1773,6 +1773,26 @@ class ApiSubmitTests(TestCase): expected = "Upload of %s OK, confirmation requests sent to:\n %s" % (name, author.formatted_email().replace('\n','')) self.assertContains(r, expected, status_code=200) + def test_api_submit_secondary_email_active(self): + person = PersonFactory() + email = EmailFactory(person=person) + r, author, name = self.post_submission('00', author=person, email=email.address) + for expected in [ + "Upload of %s OK, confirmation requests sent to:" % (name, ), + author.formatted_email().replace('\n',''), + ]: + self.assertContains(r, expected, status_code=200) + + def test_api_submit_secondary_email_inactive(self): + person = PersonFactory() + prim = person.email() + prim.primary = True + prim.save() + email = EmailFactory(person=person, active=False) + r, author, name = self.post_submission('00', author=person, email=email.address) + expected = "No such user: %s" % email.address + self.assertContains(r, expected, status_code=400) + def test_api_submit_no_user(self): email='nonexistant.user@example.org' r, author, name = self.post_submission('00', email=email) diff --git a/ietf/submit/views.py b/ietf/submit/views.py index d8b32a641..196ddb365 100644 --- a/ietf/submit/views.py +++ b/ietf/submit/views.py @@ -1,4 +1,4 @@ -# Copyright The IETF Trust 2011-2019, All Rights Reserved +# Copyright The IETF Trust 2011-2020, All Rights Reserved # -*- coding: utf-8 -*- @@ -30,7 +30,7 @@ from ietf.group.utils import group_features_group_filter from ietf.ietfauth.utils import has_role, role_required from ietf.mailtrigger.utils import gather_address_lists from ietf.message.models import Message, MessageAttachment -from ietf.person.models import Person +from ietf.person.models import Person, Email from ietf.submit.forms import ( SubmissionManualUploadForm, SubmissionAutoUploadForm, AuthorForm, SubmitterForm, EditSubmissionForm, PreapprovalForm, ReplacesForm, SubmissionEmailForm, MessageModelForm ) from ietf.submit.mail import ( send_full_url, send_manual_post_request, add_submission_email, get_reply_to ) @@ -106,10 +106,25 @@ def api_submit(request): username = form.cleaned_data['user'] user = User.objects.filter(username=username) if user.count() == 0: - return err(400, "No such user: %s" % username) - if user.count() > 1: + # See if a secondary login was being used + email = Email.objects.filter(address=username, active=True) + # The error messages don't talk about 'email', as the field we're + # looking at is still the 'username' field. + if email.count() == 0: + return err(400, "No such user: %s" % username) + elif email.count() > 1: + return err(500, "Multiple matching accounts for %s" % username) + email = email.first() + if not hasattr(email, 'person'): + return err(400, "No person matches %s" % username) + person = email.person + if not hasattr(person, 'user'): + return err(400, "No user matches: %s" % username) + user = person.user + elif user.count() > 1: return err(500, "Multiple matching accounts for %s" % username) - user = user.first() + else: + user = user.first() if not hasattr(user, 'person'): return err(400, "No person with username %s" % username) @@ -133,7 +148,7 @@ def api_submit(request): if errors: raise ValidationError(errors) - if not user.username.lower() in [ a['email'].lower() for a in authors ]: + if not username.lower() in [ a['email'].lower() for a in authors ]: raise ValidationError('Submitter %s is not one of the document authors' % user.username) submission.submitter = user.person.formatted_email()