diff --git a/static/styles/settings.scss b/static/styles/settings.scss index 68a4b8c62b..784cd67ea9 100644 --- a/static/styles/settings.scss +++ b/static/styles/settings.scss @@ -495,6 +495,7 @@ input[type=checkbox] + .inline-block { margin-bottom: 20px; } +#id_org_profile_preview, .realm-icon-section { margin-bottom: 20px; } diff --git a/static/templates/settings/organization-profile-admin.handlebars b/static/templates/settings/organization-profile-admin.handlebars index e1a30a6dd7..32a813abb5 100644 --- a/static/templates/settings/organization-profile-admin.handlebars +++ b/static/templates/settings/organization-profile-admin.handlebars @@ -45,6 +45,10 @@ id="realm_icon_delete_button">{{t 'Delete profile picture' }} + + {{t 'Preview organization profile' }} + +

{{t "Organization logo" }} diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py index 8e43ceca99..a187941e43 100644 --- a/zerver/tests/test_auth_backends.py +++ b/zerver/tests/test_auth_backends.py @@ -216,6 +216,31 @@ class AuthBackendTest(ZulipTestCase): password, realm=get_realm("zulip"))) + def test_login_preview(self) -> None: + # Test preview=true displays organization login page + # instead of redirecting to app + self.login(self.example_email("iago")) + realm = get_realm("zulip") + result = self.client_get('/login/?preview=true') + self.assertEqual(result.status_code, 200) + self.assert_in_response(realm.description, result) + self.assert_in_response(realm.name, result) + self.assert_in_response("Log in to Zulip", result) + + data = dict(description=ujson.dumps("New realm description"), + name=ujson.dumps("New Zulip")) + result = self.client_patch('/json/realm', data) + self.assert_json_success(result) + + result = self.client_get('/login/?preview=true') + self.assertEqual(result.status_code, 200) + self.assert_in_response("New realm description", result) + self.assert_in_response("New Zulip", result) + + result = self.client_get('/login/') + self.assertEqual(result.status_code, 302) + self.assertEqual(result.url, 'http://zulip.testserver') + @override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipDummyBackend',)) def test_no_backend_enabled(self) -> None: result = self.client_get('/login/') diff --git a/zerver/views/auth.py b/zerver/views/auth.py index 6aeebda73d..6e45695f0a 100644 --- a/zerver/views/auth.py +++ b/zerver/views/auth.py @@ -689,10 +689,16 @@ class TwoFactorLoginView(BaseTwoFactorLoginView): return super().done(form_list, **kwargs) def login_page(request: HttpRequest, **kwargs: Any) -> HttpResponse: + # To support previewing the Zulip login pages, we have a special option + # that disables the default behavior of redirecting logged-in users to the + # logged-in app. + is_preview = False + if request.method == "GET" and request.GET and request.GET.get('preview'): + is_preview = True if settings.TWO_FACTOR_AUTHENTICATION_ENABLED: if request.user and request.user.is_verified(): return HttpResponseRedirect(request.user.realm.uri) - elif request.user.is_authenticated: + elif request.user.is_authenticated and not is_preview: return HttpResponseRedirect(request.user.realm.uri) if is_subdomain_root_or_alias(request) and settings.ROOT_DOMAIN_LANDING_PAGE: redirect_url = reverse('zerver.views.registration.realm_redirect')