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.

storage: Hash system bots avatar files.

PieterCKc9375fb5eeb6
diff --git a/zerver/lib/avatar.py b/zerver/lib/avatar.py
index 69c12cf77d2..f33cdc6c22c 100644
--- a/zerver/lib/avatar.py
+++ b/zerver/lib/avatar.py
@@ -14,6 +14,8 @@ from zerver.lib.url_encoding import append_url_query_string
from zerver.models import UserProfile
SYSTEM_BOTS_AVATAR_FILES = {
+ # This is also used in zerver/lib/storage.py to ensure
+ # these files are hashed when served as static files.
settings.WELCOME_BOT: "images/welcome-bot.png",
settings.NOTIFICATION_BOT: "images/logo/zulip-icon-square.svg",
settings.EMAIL_GATEWAY_BOT: "images/email-gateway-bot.png",
diff --git a/zerver/lib/storage.py b/zerver/lib/storage.py
index 1710010065e..956b62ed96f 100644
--- a/zerver/lib/storage.py
+++ b/zerver/lib/storage.py
@@ -10,6 +10,8 @@ from django.core.files.base import File
from django.core.files.storage import FileSystemStorage
from typing_extensions import override
+from zerver.lib.avatar import SYSTEM_BOTS_AVATAR_FILES
+
if settings.DEBUG:
from django.contrib.staticfiles.finders import find
@@ -38,6 +40,12 @@ class IgnoreBundlesManifestStaticFilesStorage(ManifestStaticFilesStorage):
# use a no-op hash function for these already-hashed
# assets.
return name
+ if name in SYSTEM_BOTS_AVATAR_FILES.values():
+ # For these avatar files, we want to make sure they are
+ # so they can hit our Nginx caching block for static files.
+ # We don't need to worry about stale caches since system bot
+ # avatars rarely change.
+ return super().hashed_name(name, content, filename)
if name == "generated/emoji/emoji_api.json":
# Unlike most .json files, we do want to hash this file;
# its hashed URL is returned as part of the API. See