help-links: Limit billing related relative gear menu links.

In order to only generate relative links for Zulip Cloud billing
specific gear menu options in relevant help center articles, we
pass down settings.CORPORATE_ENABLED to be set as a global variable
for zerver/lib/markdown/help_relative_links.py so that self-hosted
servers' help center documentation will not have these links.
This commit is contained in:
Lauryn Menard 2024-09-24 20:32:36 +02:00 committed by Tim Abbott
parent d8fd0d8599
commit 7d21e20cb4
4 changed files with 60 additions and 11 deletions

View File

@ -10,7 +10,7 @@ don't hesitate to reach out at [sales@zulip.com](mailto:sales@zulip.com).
{tab|by-card}
{relative|gear|plans}
{relative|gear-billing|plans}
1. On the page listing Zulip Cloud plans, click the button at the bottom
of the plan you would like to purchase.
@ -21,7 +21,7 @@ don't hesitate to reach out at [sales@zulip.com](mailto:sales@zulip.com).
{!pay-by-invoice-warning.md!}
{relative|gear|plans}
{relative|gear-billing|plans}
1. On the page listing Zulip Cloud plans, click the button at the bottom
of the plan you would like to purchase.
@ -38,7 +38,7 @@ don't hesitate to reach out at [sales@zulip.com](mailto:sales@zulip.com).
{tab|desktop-web}
{relative|gear|billing}
{relative|gear-billing|billing}
{end_tabs}
@ -51,7 +51,7 @@ Free** at the end of the current billing period.
{tab|desktop-web}
{relative|gear|billing}
{relative|gear-billing|billing}
1. At the bottom of the page, click **Cancel plan**.
@ -190,7 +190,7 @@ tool.
{tab|desktop-web}
{relative|gear|billing}
{relative|gear-billing|billing}
{!manual-add-license-instructions.md!}

View File

@ -38,8 +38,6 @@ gear_info = {
],
"stats": ['<i class="zulip-icon zulip-icon-bar-chart"></i> Usage statistics', "/stats"],
"integrations": ['<i class="zulip-icon-git-pull-request"></i> Integrations', "/integrations/"],
"plans": ['<i class="zulip-icon zulip-icon-rocket"></i> Plans and pricing', "/plans/"],
"billing": ['<i class="zulip-icon zulip-icon-credit-card"></i> Billing', "/billing/"],
"about-zulip": ["About Zulip", "/#about-zulip"],
}
@ -59,6 +57,25 @@ def gear_handle_match(key: str) -> str:
return gear_instructions.format(item=item)
billing_info = {
# The pattern is key: [name, link]
# key is from REGEXP: `{relative|gear-billing|key}`
# name is what the item is called in the help menu: `Select **name**.`
# link is used for relative links: `Select [name](link).`
# Note that links are only used when billing is enabled.
"plans": ['<i class="zulip-icon zulip-icon-rocket"></i> Plans and pricing', "/plans/"],
"billing": ['<i class="zulip-icon zulip-icon-credit-card"></i> Billing', "/billing/"],
}
def billing_handle_match(key: str) -> str:
if relative_help_links and billing_help_links:
item = f"[{billing_info[key][0]}]({billing_info[key][1]})"
else:
item = f"**{billing_info[key][0]}**"
return gear_instructions.format(item=item)
help_info = {
# The pattern is key: [name, link]
# key is from REGEXP: `{relative|help|key}`
@ -190,6 +207,7 @@ def message_handle_match(key: str) -> str:
LINK_TYPE_HANDLERS = {
"gear": gear_handle_match,
"gear-billing": billing_handle_match,
"channel": channel_handle_match,
"message": message_handle_match,
"help": help_handle_match,
@ -208,11 +226,14 @@ class RelativeLinksHelpExtension(Extension):
relative_help_links: bool = False
billing_help_links: bool = False
def set_relative_help_links(value: bool) -> None:
def set_relative_help_links(relative_links: bool, billing_links: bool) -> None:
global relative_help_links
relative_help_links = value
global billing_help_links
relative_help_links = relative_links
billing_help_links = billing_links
class RelativeLinks(Preprocessor):

View File

@ -98,10 +98,12 @@ def render_markdown_path(
# We set this global hackishly
from zerver.lib.markdown.help_settings_links import set_relative_settings_links
set_relative_settings_links(bool(context is not None and context.get("html_settings_links")))
relative_links = bool(context is not None and context.get("html_settings_links"))
set_relative_settings_links(relative_links)
from zerver.lib.markdown.help_relative_links import set_relative_help_links
set_relative_help_links(bool(context is not None and context.get("html_settings_links")))
billing_relative_links = bool(context is not None and context.get("corporate_enabled"))
set_relative_help_links(relative_links, billing_relative_links)
global md_extensions, md_macro_extension
if md_extensions is None:

View File

@ -424,6 +424,32 @@ class HelpTest(ZulipTestCase):
)
self.assertNotIn("/stats", str(result.content))
def test_help_relative_gear_billing_links(self) -> None:
result = self.client_get("/help/zulip-cloud-billing")
self.assertIn(
'<a href="/plans/"><i class="zulip-icon zulip-icon-rocket"></i> Plans and pricing</a>',
str(result.content),
)
self.assertEqual(result.status_code, 200)
with self.settings(CORPORATE_ENABLED=False):
result = self.client_get("/help/zulip-cloud-billing")
self.assertEqual(result.status_code, 200)
self.assertIn(
'<strong><i class="zulip-icon zulip-icon-rocket"></i> Plans and pricing</strong>',
str(result.content),
)
self.assertNotIn('<a href="/plans/">', str(result.content))
with self.settings(ROOT_DOMAIN_LANDING_PAGE=True):
result = self.client_get("/help/zulip-cloud-billing", subdomain="")
self.assertEqual(result.status_code, 200)
self.assertIn(
'<strong><i class="zulip-icon zulip-icon-rocket"></i> Plans and pricing</strong>',
str(result.content),
)
self.assertNotIn('a href="/plans/">', str(result.content))
def test_help_relative_links_for_stream(self) -> None:
result = self.client_get("/help/message-a-channel-by-email")
self.assertIn(