auth: Separate code to get all emails from `get_verified_emails`.

This separates the part of code that gets all the emails associated
to GitHub from `get_verified_emails` in `GitHubAuthBackend`.
Improves readability of code and acts as a preparatory commit for
extending the template for "choose email" in GitHub auth flow to also
list any unverified emails that have an associated Zulip account in
the organization.
This commit is contained in:
Dinesh 2020-03-28 15:29:06 +05:30 committed by Tim Abbott
parent 5f15af2382
commit 4a07a6def7
1 changed files with 4 additions and 1 deletions

View File

@ -1363,7 +1363,7 @@ class GitHubAuthBackend(SocialAuthMixin, GithubOAuth2):
sort_order = 100
display_icon = "/static/images/landing-page/logos/github-icon.png"
def get_verified_emails(self, *args: Any, **kwargs: Any) -> List[str]:
def get_all_associated_email_objects(self, *args: Any, **kwargs: Any) -> List[Dict[str, Any]]:
access_token = kwargs["response"]["access_token"]
try:
emails = self._user_data(access_token, '/emails')
@ -1372,7 +1372,10 @@ class GitHubAuthBackend(SocialAuthMixin, GithubOAuth2):
# path, since the outcome will be the same as any other
# case without any verified emails
emails = []
return emails
def get_verified_emails(self, *args: Any, **kwargs: Any) -> List[str]:
emails = self.get_all_associated_email_objects(*args, **kwargs)
verified_emails: List[str] = []
for email_obj in self.filter_usable_emails(emails):
# social_associate_user_helper assumes that the first email in