diff --git a/help/zulip-cloud-billing.md b/help/zulip-cloud-billing.md index 6212ac473e..907323f4e1 100644 --- a/help/zulip-cloud-billing.md +++ b/help/zulip-cloud-billing.md @@ -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!} diff --git a/zerver/lib/markdown/help_relative_links.py b/zerver/lib/markdown/help_relative_links.py index baaf7b7a8b..52511964a5 100644 --- a/zerver/lib/markdown/help_relative_links.py +++ b/zerver/lib/markdown/help_relative_links.py @@ -38,8 +38,6 @@ gear_info = { ], "stats": [' Usage statistics', "/stats"], "integrations": [' Integrations', "/integrations/"], - "plans": [' Plans and pricing', "/plans/"], - "billing": [' 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": [' Plans and pricing', "/plans/"], + "billing": [' 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): diff --git a/zerver/lib/templates.py b/zerver/lib/templates.py index d0b7c022ec..73cb8480dd 100644 --- a/zerver/lib/templates.py +++ b/zerver/lib/templates.py @@ -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: diff --git a/zerver/tests/test_docs.py b/zerver/tests/test_docs.py index b7e8e87193..2c42ecb95d 100644 --- a/zerver/tests/test_docs.py +++ b/zerver/tests/test_docs.py @@ -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( + ' Plans and pricing', + 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( + ' Plans and pricing', + str(result.content), + ) + self.assertNotIn('', 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( + ' Plans and pricing', + 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(