auth: GitHubAuthBackend.get_verified_emails returns user's all emails.

The email_list returned has the primary email as the first element.
Testing: The order of the emails in the test was changed to put a
verified email before the primary one. The tests would fail without
this commit's change after the changes in the order of test emails.
This commit is contained in:
Shubham Padia 2018-07-10 15:33:42 +05:30 committed by Tim Abbott
parent 2fa77d9d54
commit d95364b94f
2 changed files with 13 additions and 7 deletions

View File

@ -477,14 +477,18 @@ class GitHubAuthBackendTest(ZulipTestCase):
primary=True),
]
else:
# Keeping a verified email before the primary email makes sure
# get_verified_emails puts the primary email at the start of the
# email list returned as social_associate_user_helper assumes the
# first email as the primary email.
email_data = [
dict(email="notprimary@example.com",
verified=True),
dict(email=account_data_dict["email"],
verified=True,
primary=True),
dict(email="ignored@example.com",
verified=False),
dict(email="notprimary@example.com",
verified=True),
]
# We register callbacks for the key URLs on github.com that
# /complete/github will call

View File

@ -598,14 +598,16 @@ class GitHubAuthBackend(SocialAuthMixin, GithubOAuth2):
# case without any verified emails
emails = []
verified_emails = []
verified_emails = [] # type: List[str]
for email_obj in emails:
if not email_obj.get("verified"):
continue
# TODO: When we add a screen to let the user select an email, remove this line.
if not email_obj.get("primary"):
continue
verified_emails.append(email_obj["email"])
# social_associate_user_helper assumes that the first email in
# verified_emails is primary.
if email_obj.get("primary"):
verified_emails.insert(0, email_obj["email"])
else:
verified_emails.append(email_obj["email"])
return verified_emails