From 051dab58eaeedd475109072aa4c7b5dfbcfbd7cc Mon Sep 17 00:00:00 2001 From: Vishnu KS Date: Fri, 5 Mar 2021 23:09:02 +0530 Subject: [PATCH] navbar: Add gear menu advertisement for sponsoring zulip. --- templates/zerver/app/navbar.html | 7 +++++++ zerver/lib/home.py | 14 +++++++++++++- zerver/tests/test_home.py | 24 ++++++++++++++++++++++++ zerver/views/home.py | 2 ++ zproject/default_settings.py | 1 + zproject/prod_settings_template.py | 3 +++ 6 files changed, 50 insertions(+), 1 deletion(-) diff --git a/templates/zerver/app/navbar.html b/templates/zerver/app/navbar.html index 0fc12c140e..de7f9c66ab 100644 --- a/templates/zerver/app/navbar.html +++ b/templates/zerver/app/navbar.html @@ -136,6 +136,13 @@ {% endif %} + {% if promote_sponsoring_zulip %} +
  • + + {{ _('Support Zulip') }} + +
  • + {% endif %} {% if show_plans %}
  • diff --git a/zerver/lib/home.py b/zerver/lib/home.py index 7afff29416..b3729d18f5 100644 --- a/zerver/lib/home.py +++ b/zerver/lib/home.py @@ -101,6 +101,15 @@ def get_bot_types(user_profile: Optional[UserProfile]) -> List[Dict[str, object] return bot_types +def promote_sponsoring_zulip_in_realm(realm: Realm) -> bool: + if not settings.PROMOTE_SPONSORING_ZULIP: + return False + + # If PROMOTE_SPONSORING_ZULIP is enabled, advertise sponsoring + # Zulip in the gear menu of non-paying organizations. + return realm.plan_type in [Realm.STANDARD_FREE, Realm.SELF_HOSTED] + + def get_billing_info(user_profile: UserProfile) -> BillingInfo: show_billing = False show_plans = False @@ -118,7 +127,10 @@ def get_billing_info(user_profile: UserProfile) -> BillingInfo: if not user_profile.is_guest and user_profile.realm.plan_type == Realm.LIMITED: show_plans = True - return BillingInfo(show_billing=show_billing, show_plans=show_plans) + return BillingInfo( + show_billing=show_billing, + show_plans=show_plans, + ) def get_user_permission_info(user_profile: Optional[UserProfile]) -> UserPermissionInfo: diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py index 170f81f8d5..7d4fcc5b57 100644 --- a/zerver/tests/test_home.py +++ b/zerver/tests/test_home.py @@ -805,6 +805,30 @@ class HomeTest(ZulipTestCase): result_html = self._get_home_page().content.decode("utf-8") self.assertNotIn("Plans", result_html) + def test_show_support_zulip(self) -> None: + realm = get_realm("zulip") + + self.login("hamlet") + + result_html = self._get_home_page().content.decode("utf-8") + self.assertIn("Support Zulip", result_html) + + do_change_plan_type(realm, Realm.STANDARD_FREE, acting_user=None) + result_html = self._get_home_page().content.decode("utf-8") + self.assertIn("Support Zulip", result_html) + + with self.settings(PROMOTE_SPONSORING_ZULIP=False): + result_html = self._get_home_page().content.decode("utf-8") + self.assertNotIn("Support Zulip", result_html) + + do_change_plan_type(realm, Realm.LIMITED, acting_user=None) + result_html = self._get_home_page().content.decode("utf-8") + self.assertNotIn("Support Zulip", result_html) + + do_change_plan_type(realm, Realm.STANDARD, acting_user=None) + result_html = self._get_home_page().content.decode("utf-8") + self.assertNotIn("Support Zulip", result_html) + def test_desktop_home(self) -> None: self.login("hamlet") result = self.client_get("/desktop_home") diff --git a/zerver/views/home.py b/zerver/views/home.py index c487edbb32..e049bc2040 100644 --- a/zerver/views/home.py +++ b/zerver/views/home.py @@ -16,6 +16,7 @@ from zerver.lib.home import ( build_page_params_for_home_page_load, get_billing_info, get_user_permission_info, + promote_sponsoring_zulip_in_realm, ) from zerver.lib.push_notifications import num_push_devices_for_user from zerver.lib.streams import access_stream_by_name @@ -231,6 +232,7 @@ def home_real(request: HttpRequest) -> HttpResponse: "search_pills_enabled": settings.SEARCH_PILLS_ENABLED, "show_invites": show_invites, "show_add_streams": show_add_streams, + "promote_sponsoring_zulip": promote_sponsoring_zulip_in_realm(realm), "show_billing": billing_info.show_billing, "corporate_enabled": settings.CORPORATE_ENABLED, "show_plans": billing_info.show_plans, diff --git a/zproject/default_settings.py b/zproject/default_settings.py index a8d726d8d5..5a28357ecf 100644 --- a/zproject/default_settings.py +++ b/zproject/default_settings.py @@ -180,6 +180,7 @@ PASSWORD_MIN_GUESSES = 10000 PUSH_NOTIFICATION_BOUNCER_URL: Optional[str] = None PUSH_NOTIFICATION_REDACT_CONTENT = False SUBMIT_USAGE_STATISTICS = True +PROMOTE_SPONSORING_ZULIP = True RATE_LIMITING = True RATE_LIMITING_AUTHENTICATE = True SEND_LOGIN_EMAILS = True diff --git a/zproject/prod_settings_template.py b/zproject/prod_settings_template.py index a73b41ba76..a6d4efab5b 100644 --- a/zproject/prod_settings_template.py +++ b/zproject/prod_settings_template.py @@ -611,6 +611,9 @@ SOCIAL_AUTH_SAML_SUPPORT_CONTACT = { ## Defaults to True if and only if the Mobile Push Notifications Service is enabled. # SUBMIT_USAGE_STATISTICS = True +## Whether to lightly advertise sponsoring Zulip in the gear menu. +# PROMOTE_SPONSORING_ZULIP = True + ## Controls whether session cookies expire when the browser closes SESSION_EXPIRE_AT_BROWSER_CLOSE = False