navbar: Add gear menu advertisement for sponsoring zulip.

This commit is contained in:
Vishnu KS 2021-03-05 23:09:02 +05:30 committed by Tim Abbott
parent b0f8bbfbd4
commit 051dab58ea
6 changed files with 50 additions and 1 deletions

View File

@ -136,6 +136,13 @@
</a> </a>
</li> </li>
{% endif %} {% endif %}
{% if promote_sponsoring_zulip %}
<li role="presentation">
<a href="https://github.com/sponsors/zulip" target="_blank" role="menuitem">
<i class="fa fa-heart" aria-hidden="true"></i> {{ _('Support Zulip') }}
</a>
</li>
{% endif %}
{% if show_plans %} {% if show_plans %}
<li role="presentation"> <li role="presentation">
<a href="/plans" target="_blank" rel="noopener noreferrer" role="menuitem"> <a href="/plans" target="_blank" rel="noopener noreferrer" role="menuitem">

View File

@ -101,6 +101,15 @@ def get_bot_types(user_profile: Optional[UserProfile]) -> List[Dict[str, object]
return bot_types 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: def get_billing_info(user_profile: UserProfile) -> BillingInfo:
show_billing = False show_billing = False
show_plans = 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: if not user_profile.is_guest and user_profile.realm.plan_type == Realm.LIMITED:
show_plans = True 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: def get_user_permission_info(user_profile: Optional[UserProfile]) -> UserPermissionInfo:

View File

@ -805,6 +805,30 @@ class HomeTest(ZulipTestCase):
result_html = self._get_home_page().content.decode("utf-8") result_html = self._get_home_page().content.decode("utf-8")
self.assertNotIn("Plans", result_html) 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: def test_desktop_home(self) -> None:
self.login("hamlet") self.login("hamlet")
result = self.client_get("/desktop_home") result = self.client_get("/desktop_home")

View File

@ -16,6 +16,7 @@ from zerver.lib.home import (
build_page_params_for_home_page_load, build_page_params_for_home_page_load,
get_billing_info, get_billing_info,
get_user_permission_info, get_user_permission_info,
promote_sponsoring_zulip_in_realm,
) )
from zerver.lib.push_notifications import num_push_devices_for_user from zerver.lib.push_notifications import num_push_devices_for_user
from zerver.lib.streams import access_stream_by_name 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, "search_pills_enabled": settings.SEARCH_PILLS_ENABLED,
"show_invites": show_invites, "show_invites": show_invites,
"show_add_streams": show_add_streams, "show_add_streams": show_add_streams,
"promote_sponsoring_zulip": promote_sponsoring_zulip_in_realm(realm),
"show_billing": billing_info.show_billing, "show_billing": billing_info.show_billing,
"corporate_enabled": settings.CORPORATE_ENABLED, "corporate_enabled": settings.CORPORATE_ENABLED,
"show_plans": billing_info.show_plans, "show_plans": billing_info.show_plans,

View File

@ -180,6 +180,7 @@ PASSWORD_MIN_GUESSES = 10000
PUSH_NOTIFICATION_BOUNCER_URL: Optional[str] = None PUSH_NOTIFICATION_BOUNCER_URL: Optional[str] = None
PUSH_NOTIFICATION_REDACT_CONTENT = False PUSH_NOTIFICATION_REDACT_CONTENT = False
SUBMIT_USAGE_STATISTICS = True SUBMIT_USAGE_STATISTICS = True
PROMOTE_SPONSORING_ZULIP = True
RATE_LIMITING = True RATE_LIMITING = True
RATE_LIMITING_AUTHENTICATE = True RATE_LIMITING_AUTHENTICATE = True
SEND_LOGIN_EMAILS = True SEND_LOGIN_EMAILS = True

View File

@ -611,6 +611,9 @@ SOCIAL_AUTH_SAML_SUPPORT_CONTACT = {
## Defaults to True if and only if the Mobile Push Notifications Service is enabled. ## Defaults to True if and only if the Mobile Push Notifications Service is enabled.
# SUBMIT_USAGE_STATISTICS = True # 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 ## Controls whether session cookies expire when the browser closes
SESSION_EXPIRE_AT_BROWSER_CLOSE = False SESSION_EXPIRE_AT_BROWSER_CLOSE = False