Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
help-links: Limit billing related relative gear menu links.
Lauryn Menard7d21e20cb43c
diff --git a/help/zulip-cloud-billing.md b/help/zulip-cloud-billing.mdindex 6212ac473ed..907323f4e1d 100644--- a/help/zulip-cloud-billing.md+++ b/help/zulip-cloud-billing.md@@ -10,7 +10,7 @@ don't hesitate to reach out at [[email protected]](mailto:[email protected]).{tab|by-card}-{relative|gear|plans}+{relative|gear-billing|plans}1. On the page listing Zulip Cloud plans, click the button at the bottomof the plan you would like to purchase.@@ -21,7 +21,7 @@ don't hesitate to reach out at [[email protected]](mailto:[email protected]).{!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 bottomof the plan you would like to purchase.@@ -38,7 +38,7 @@ don't hesitate to reach out at [[email protected]](mailto:[email protected]).{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.pyindex baaf7b7a8b5..52511964a55 100644--- a/zerver/lib/markdown/help_relative_links.py+++ b/zerver/lib/markdown/help_relative_links.py@@ -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_linksclass RelativeLinks(Preprocessor):diff --git a/zerver/lib/templates.py b/zerver/lib/templates.pyindex d0b7c022ec0..73cb8480dd5 100644--- a/zerver/lib/templates.py+++ b/zerver/lib/templates.py@@ -98,10 +98,12 @@ def render_markdown_path(# We set this global hackishlyfrom 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_extensionif md_extensions is None:diff --git a/zerver/tests/test_docs.py b/zerver/tests/test_docs.pyindex b7e8e87193a..2c42ecb95d0 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(+ '<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(