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
3030from ietf .ietfauth .utils import has_role , role_required
3131from ietf .mailtrigger .utils import gather_address_lists
3232from ietf .message .models import Message , MessageAttachment
33- from ietf .person .models import Person
33+ from ietf .person .models import Person , Email
3434from ietf .submit .forms import ( SubmissionManualUploadForm , SubmissionAutoUploadForm , AuthorForm ,
3535 SubmitterForm , EditSubmissionForm , PreapprovalForm , ReplacesForm , SubmissionEmailForm , MessageModelForm )
3636from 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