Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

integrations: Fall back to the Zulip logo when an integration has none.

Niloth P2995fb382279
diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.py
index 09d1affd52b..61a722b79b6 100644
--- a/zerver/lib/integrations.py
+++ b/zerver/lib/integrations.py
@@ -145,6 +145,7 @@ def get_screenshot_configs(
class Integration:
DEFAULT_LOGO_STATIC_PATH_PNG = "images/integrations/logos/{name}.png"
DEFAULT_LOGO_STATIC_PATH_SVG = "images/integrations/logos/{name}.svg"
+ ZULIP_LOGO_STATIC_PATH_PNG = "images/logo/zulip-icon-128x128.png"
DEFAULT_BOT_AVATAR_PATH = "images/integrations/bot_avatars/{name}.png"
DEFAULT_DOC_PATH = "zerver/integrations/{name}.md"
@@ -157,7 +158,6 @@ class Integration:
webhook_screenshot_configs: list[WebhookScreenshotConfig] | None = None,
client_name: str | None = None,
logo: str | None = None,
- fallback_logo_path: str | None = None,
secondary_line_text: str | None = None,
display_name: str | None = None,
doc: str | None = None,
@@ -199,7 +199,7 @@ class Integration:
)
self.categories = [CATEGORIES[c] for c in categories]
- self.logo_path = logo if logo is not None else self.get_logo_path(fallback_logo_path)
+ self.logo_path = logo if logo is not None else self.get_logo_path()
self.logo_url = staticfiles_storage.url(self.logo_path)
if display_name is None:
@@ -219,21 +219,15 @@ class Integration:
"hubot",
)
- def get_logo_path(self, fallback_logo_path: str | None = None) -> str:
+ def get_logo_path(self) -> str:
paths_to_check = [
self.DEFAULT_LOGO_STATIC_PATH_SVG.format(name=self.name),
self.DEFAULT_LOGO_STATIC_PATH_PNG.format(name=self.name),
]
- if fallback_logo_path is not None:
- paths_to_check.append(fallback_logo_path)
-
for potential_path in paths_to_check:
if os.path.isfile(static_path(potential_path)):
return potential_path
-
- raise AssertionError(
- f"Could not find a logo for integration {self.name}. Paths checked: {', '.join(paths_to_check)}"
- )
+ return self.ZULIP_LOGO_STATIC_PATH_PNG
def get_bot_avatar_path(self) -> str:
name = os.path.splitext(os.path.basename(self.logo_path))[0]
@@ -243,7 +237,6 @@ class Integration:
class BotIntegration(Integration):
DEFAULT_LOGO_STATIC_PATH_PNG = "generated/bots/{name}/logo.png"
DEFAULT_LOGO_STATIC_PATH_SVG = "generated/bots/{name}/logo.svg"
- ZULIP_LOGO_STATIC_PATH_PNG = "images/logo/zulip-icon-128x128.png"
DEFAULT_DOC_PATH = "{name}/doc.md"
def __init__(
@@ -264,7 +257,6 @@ class BotIntegration(Integration):
fixtureless_screenshot_config_options=fixtureless_screenshot_config_options,
secondary_line_text=secondary_line_text,
logo=logo,
- fallback_logo_path=self.ZULIP_LOGO_STATIC_PATH_PNG,
)
if display_name is None:
@@ -460,12 +452,10 @@ class EmbeddedBotIntegration(Integration):
"""
DEFAULT_CLIENT_NAME = "Zulip{name}EmbeddedBot"
- ZULIP_LOGO_STATIC_PATH_PNG = "images/logo/zulip-icon-128x128.png"
def __init__(self, name: str, *args: Any, **kwargs: Any) -> None:
assert kwargs.get("client_name") is None
kwargs["client_name"] = self.DEFAULT_CLIENT_NAME.format(name=name.title())
- kwargs["fallback_logo_path"] = self.ZULIP_LOGO_STATIC_PATH_PNG
super().__init__(name, *args, **kwargs)
@override
diff --git a/zerver/tests/test_integrations.py b/zerver/tests/test_integrations.py
index d8b800323f0..bcb91930eef 100644
--- a/zerver/tests/test_integrations.py
+++ b/zerver/tests/test_integrations.py
@@ -43,23 +43,17 @@ class IntegrationsTestCase(ZulipTestCase):
self.assertEqual(image_path, "static/images/integrations/ci/002.png")
def test_get_logo_path(self) -> None:
- # Test with an integration that passed logo as an argument
+ # Test integration with logo argument, so no logo in default paths
integration = INTEGRATIONS["slack_incoming"]
- with self.assertRaises(AssertionError):
- integration.get_logo_path()
+ self.assertEqual(integration.get_logo_path(), Integration.ZULIP_LOGO_STATIC_PATH_PNG)
# Test with an integration that has only a PNG option
integration = INTEGRATIONS["onyx"]
self.assertEqual(integration.get_logo_path(), "images/integrations/logos/onyx.png")
# Test the fallback logo with an embedded integration without a logo
- ZULIP_LOGO_STATIC_PATH_PNG = "images/logo/zulip-icon-128x128.png"
integration = EMBEDDED_BOTS[0]
- with self.assertRaises(AssertionError):
- integration.get_logo_path()
- self.assertEqual(
- integration.get_logo_path(ZULIP_LOGO_STATIC_PATH_PNG), ZULIP_LOGO_STATIC_PATH_PNG
- )
+ self.assertEqual(integration.get_logo_path(), Integration.ZULIP_LOGO_STATIC_PATH_PNG)
# Test with a bot integration that has a logo
# They use different DEFAULT_* paths.
@@ -74,8 +68,12 @@ class IntegrationsTestCase(ZulipTestCase):
integration.get_bot_avatar_path(), "images/integrations/bot_avatars/prometheus.png"
)
- with self.assertRaises(AssertionError):
- integration = Integration("alertmanager", ["misc"])
+ # bot avatar path for an integration using the fallback Zulip logo
+ integration = Integration("alertmanager", ["misc"])
+ self.assertEqual(
+ integration.get_bot_avatar_path(),
+ "images/integrations/bot_avatars/zulip-icon-128x128.png",
+ )
def test_no_missing_doc_screenshot_config(self) -> None:
integration_names = {