From f109dcce9c54db56a40fc9d3623e087dfa9f310e Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Sat, 3 Aug 2019 14:15:32 +0200 Subject: [PATCH] auth: Add logic for avatars to the GitHub auth email selection page. For the emails that are associated to an existing account in an organisation, the avatars will be displayed in the email selection page. This includes avatar data in what is passed to the page. Added `avatar_urls` to the context in `test_templates.py`. --- zerver/tests/test_templates.py | 1 + zproject/backends.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/zerver/tests/test_templates.py b/zerver/tests/test_templates.py index 24eaa9730e..7712110538 100644 --- a/zerver/tests/test_templates.py +++ b/zerver/tests/test_templates.py @@ -181,6 +181,7 @@ class TemplateTestCase(ZulipTestCase): request=RequestFactory().get("/"), invite_as={"MEMBER": 1}, max_file_upload_size = 25, + avatar_urls={"john@gmail.com": "www.zulip.com"}, ) context.update(kwargs) diff --git a/zproject/backends.py b/zproject/backends.py index b6a509ba4b..79df81c801 100644 --- a/zproject/backends.py +++ b/zproject/backends.py @@ -38,7 +38,7 @@ from social_core.exceptions import AuthFailed, SocialAuthBaseException from zerver.lib.actions import do_create_user, do_reactivate_user, do_deactivate_user, \ do_update_user_custom_profile_data, validate_email_for_realm -from zerver.lib.avatar import is_avatar_new +from zerver.lib.avatar import is_avatar_new, avatar_url from zerver.lib.avatar_hash import user_avatar_content_hash from zerver.lib.dev_ldap_directory import init_fakeldap from zerver.lib.request import JsonableError @@ -658,10 +658,17 @@ def social_associate_user_helper(backend: BaseAuth, return_data: Dict[str, Any], chosen_email = backend.strategy.request_data().get('email') if not chosen_email: + avatars = {} # Dict[str, str] + for email in verified_emails: + existing_account = common_get_active_user(email, realm, {}) + if existing_account is not None: + avatars[email] = avatar_url(existing_account) + return render(backend.strategy.request, 'zerver/social_auth_select_email.html', context = { 'primary_email': verified_emails[0], 'verified_non_primary_emails': verified_emails[1:], - 'backend': 'github' + 'backend': 'github', + 'avatar_urls': avatars, }) try: