mirror of
https://github.com/zulip/zulip.git
synced 2025-11-16 03:41:58 +00:00
avatar: Ensure system bots' avatar URLs follow convention.
Previously, requesting system bots URLs did not return any -medium.png variants and SVG file was also used for notification bots' avatar, which was problematic. In this commit, the -medium.png variants is added for the avatars of system bots and zulip-icon-square.svg is also converted into notification-bot.png for the notification bot. The get_avatar_url method has been updated to return the "medium" file variants for the system bots. Additionally, the system bots' avatar files is moved to a dedicated directory to simplify the hashing logic for these files. Now, all files in the "images/static_avatars/" directory will be hashed.
This commit is contained in:
@@ -12,14 +12,11 @@ from zerver.lib.thumbnail import MEDIUM_AVATAR_SIZE
|
||||
from zerver.lib.upload import get_avatar_url
|
||||
from zerver.lib.url_encoding import append_url_query_string
|
||||
from zerver.models import UserProfile
|
||||
from zerver.models.users import is_cross_realm_bot_email
|
||||
|
||||
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",
|
||||
}
|
||||
STATIC_AVATARS_DIR = "images/static_avatars/"
|
||||
|
||||
DEFAULT_AVATAR_FILE = "images/default-avatar.png"
|
||||
|
||||
|
||||
def avatar_url(
|
||||
@@ -36,6 +33,22 @@ def avatar_url(
|
||||
)
|
||||
|
||||
|
||||
def get_system_bots_avatar_file_name(email: str) -> str:
|
||||
system_bot_avatar_name_map = {
|
||||
settings.WELCOME_BOT: "welcome-bot",
|
||||
settings.NOTIFICATION_BOT: "notification-bot",
|
||||
settings.EMAIL_GATEWAY_BOT: "emailgateway",
|
||||
}
|
||||
return urljoin(STATIC_AVATARS_DIR, system_bot_avatar_name_map.get(email, "unknown"))
|
||||
|
||||
|
||||
def get_static_avatar_url(email: str, medium: bool) -> str:
|
||||
avatar_file_name = get_system_bots_avatar_file_name(email)
|
||||
avatar_file_name += "-medium.png" if medium else ".png"
|
||||
|
||||
return staticfiles_storage.url(avatar_file_name)
|
||||
|
||||
|
||||
def get_avatar_field(
|
||||
user_id: int,
|
||||
realm_id: int,
|
||||
@@ -63,9 +76,8 @@ def get_avatar_field(
|
||||
"""
|
||||
|
||||
# System bots have hardcoded avatars
|
||||
system_bot_avatar = SYSTEM_BOTS_AVATAR_FILES.get(email)
|
||||
if system_bot_avatar:
|
||||
return staticfiles_storage.url(system_bot_avatar)
|
||||
if is_cross_realm_bot_email(email):
|
||||
return get_static_avatar_url(email, medium)
|
||||
|
||||
"""
|
||||
If our client knows how to calculate gravatar hashes, we
|
||||
|
||||
Reference in New Issue
Block a user