Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
auth: Make apple log in and sign up buttons consistent with others.
Dinesh0445311430b7
diff --git a/static/styles/portico/portico-signin.scss b/static/styles/portico/portico-signin.scssindex c456b1a3102..569e2c0d1f9 100644--- a/static/styles/portico/portico-signin.scss+++ b/static/styles/portico/portico-signin.scss@@ -699,29 +699,6 @@ button.login-social-button {}}-/*-Apple is very particular about the appearance of its authentication-buttons, which means we cannot use our generic label+icon system for-their authentication backend while complying with their policies.--So here we use the buttons provided by Apple, which include the sign-in text (Sign in with Apple/Continue with Apple). To make these-consistent with other buttons, we request buttons of size 328x50 and-the following styling sets the appropriate width and height to make it-fit with other other social authentication buttons. We also set the-font size to zero to hide the text our own code in the-login/registration pages would generate, to avoid extra conditionals-in the HTML templates.-*/-button#login_auth_button_apple,-button#register_auth_button_apple {- width: 328px;- height: 50px;- background-size: auto 100%;- background-position: 0px 100%;- font-size: 0px;-}-#find-account-section {text-decoration: none;font-weight: 600;diff --git a/templates/zerver/accounts_home.html b/templates/zerver/accounts_home.htmlindex 7a1a76606b4..ff26a891836 100644--- a/templates/zerver/accounts_home.html+++ b/templates/zerver/accounts_home.html@@ -78,8 +78,7 @@ page can be easily identified in it's respective JavaScript file --><form class="form-inline" action="{{ backend.signup_url }}" method="get"><input type='hidden' name='multiuse_object_key' value='{{ multiuse_object_key }}' /><button id="register_{{ backend.button_id_suffix }}" class="login-social-button full-width"- {% if backend.display_name == "Apple" %} style="background-image:url(https://appleid.cdn-apple.com/appleid/button/?width=328&height=50&color=white&locale={{ apple_locale }}&type=continue)"- {% elif backend.display_icon %} style="background-image:url({{ backend.display_icon }})" {% endif %}>+ {% if backend.display_icon %} style="background-image:url({{ backend.display_icon }})" {% endif %}>{{ _('Sign up with %(identity_provider)s', identity_provider=backend.display_name) }}</button></form>diff --git a/templates/zerver/login.html b/templates/zerver/login.htmlindex 8410d45d918..761dfdbd615 100644--- a/templates/zerver/login.html+++ b/templates/zerver/login.html@@ -114,9 +114,7 @@ page can be easily identified in it's respective JavaScript file. --><form class="social_login_form form-inline" action="{{ backend.login_url }}" method="get"><input type="hidden" name="next" value="{{ next }}"><button id="login_{{ backend.button_id_suffix }}" class="login-social-button"- {% if backend.display_name == "Apple" %} style="background-image: url(https://appleid.cdn-apple.com/appleid/button/?width=328&height=50&color=white&locale={{ apple_locale }});"- {% elif backend.display_icon %} style="background-image:url({{ backend.display_icon }})" {% endif %}>- {{ _('Log in with %(identity_provider)s', identity_provider=backend.display_name) }}+ {% if backend.display_icon %} style="background-image:url({{ backend.display_icon }})" {% endif %}> {{ _('Log in with %(identity_provider)s', identity_provider=backend.display_name) }}</button></form></div>diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.pyindex 69a64db2bdd..aef1121d6ef 100644--- a/tools/linter_lib/custom_check.py+++ b/tools/linter_lib/custom_check.py@@ -499,8 +499,6 @@ html_rules: List["Rule"] = whitespace_rules + prose_style_rules + ['good_lines': ['<input class="stream-list-filter" type="text" placeholder="{{ _(\'Search streams\') }}" />'],'bad_lines': ['<input placeholder="foo">']},{'pattern': '={',- # TODO: Improve the Apple auth patterns so we can remove this.- 'exclude_pattern': 'appleid.cdn-apple.com/appleid/button','description': "Likely missing quoting in HTML attribute",'good_lines': ['<a href="{{variable}}">'],'bad_lines': ['<a href={{variable}}>']},diff --git a/zerver/context_processors.py b/zerver/context_processors.pyindex 34bbc538dc7..561aa4289e0 100644--- a/zerver/context_processors.py+++ b/zerver/context_processors.py@@ -18,7 +18,6 @@ from zerver.lib.subdomains import get_subdomainfrom zerver.models import Realm, UserProfile, get_realmfrom zproject.backends import (AUTH_BACKEND_NAME_MAP,- AppleAuthBackend,any_social_backend_enabled,auth_enabled_helper,get_external_method_dicts,@@ -168,7 +167,6 @@ def login_context(request: HttpRequest) -> Dict[str, Any]:'password_auth_enabled': password_auth_enabled(realm),'any_social_backend_enabled': any_social_backend_enabled(realm),'two_factor_authentication_enabled': settings.TWO_FACTOR_AUTHENTICATION_ENABLED,- 'apple_locale': AppleAuthBackend.get_apple_locale(request.LANGUAGE_CODE),}if realm is not None and realm.description:diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.pyindex d48ee8d2eea..0172c1c9e7d 100644--- a/zerver/tests/test_auth_backends.py+++ b/zerver/tests/test_auth_backends.py@@ -2017,25 +2017,6 @@ class AppleIdAuthBackendTest(AppleAuthMixin, SocialAuthBase):with self.settings(AUTHENTICATION_BACKENDS=('zproject.backends.AppleAuthBackend',)):self.assertTrue(apple_auth_enabled())- def test_get_apple_locale(self) -> None:- language_locale = [('ar', 'ar_SA'), ('ca', 'ca_ES'), ('cs', 'cs_CZ'),- ('da', 'da_DK'), ('de', 'de_DE'), ('el', 'el_GR'),- ('en', 'en_US'), ('es', 'es_ES'), ('fi', 'fi_FI'),- ('fr', 'fr_FR'), ('hr', 'hr_HR'), ('hu', 'hu_HU'),- ('id', 'id_ID'), ('it', 'it_IT'), ('iw', 'iw_IL'),- ('ja', 'ja_JP'), ('ko', 'ko_KR'), ('ms', 'ms_MY'),- ('nl', 'nl_NL'), ('no', 'no_NO'), ('pl', 'pl_PL'),- ('pt', 'pt_PT'), ('ro', 'ro_RO'), ('ru', 'ru_RU'),- ('sk', 'sk_SK'), ('sv', 'sv_SE'), ('th', 'th_TH'),- ('tr', 'tr_TR'), ('uk', 'uk_UA'), ('vi', 'vi_VI'),- ('zh', 'zh_CN')]-- for language_code, locale in language_locale:- self.assertEqual(AppleAuthBackend.get_apple_locale(language_code), locale)-- # return 'en_US' if invalid `language_code` is given.- self.assertEqual(AppleAuthBackend.get_apple_locale(':)'), 'en_US')-def test_auth_registration_with_no_name_sent_from_apple(self) -> None:"""Apple doesn't send the name in consecutive attempts if user registrationdiff --git a/zproject/backends.py b/zproject/backends.pyindex 4b22b1f6e74..a5034ba1087 100644--- a/zproject/backends.py+++ b/zproject/backends.py@@ -1548,6 +1548,7 @@ class AppleAuthBackend(SocialAuthMixin, AppleIdAuth):sort_order = 10name = "apple"auth_backend_name = "Apple"+ display_icon = "/static/images/landing-page/logos/apple-icon.png"# Apple only sends `name` in its response the first time a user# tries to sign up, so we won't have it in consecutive attempts.@@ -1556,28 +1557,6 @@ class AppleAuthBackend(SocialAuthMixin, AppleIdAuth):full_name_validated = TrueREDIS_EXPIRATION_SECONDS = 60*10- @staticmethod- def get_apple_locale(django_language_code: str) -> str:- '''- Get the suitable apple supported locale with language code- for the Sign in / Continue with Apple buttons it provides.- '''- # The following is a list of locale values supported by Apple to send- # as params to URL which renders "Sign in with Apple" and "Continue with Apple"- # buttons. Gathered from- # https://developer.apple.com/documentation/signinwithapplejs/incorporating_sign_in_with_apple_into_other_platforms .- supported_locales = ['ar_SA', 'ca_ES', 'cs_CZ', 'da_DK', 'de_DE',- 'el_GR', 'en_US', 'es_ES', 'fi_FI', 'fr_FR',- 'hr_HR', 'hu_HU', 'id_ID', 'it_IT', 'iw_IL',- 'ja_JP', 'ko_KR', 'ms_MY', 'nl_NL', 'no_NO',- 'pl_PL', 'pt_PT', 'ro_RO', 'ru_RU', 'sk_SK',- 'sv_SE', 'th_TH', 'tr_TR', 'uk_UA', 'vi_VI',- 'zh_CN']- for locale in supported_locales:- if django_language_code in locale:- return locale- return 'en_US'-def is_native_flow(self) -> bool:return self.strategy.request_data().get('native_flow', False)