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.

users: Fix uploading user avatars.

Sahil Batra5ef14c3a8e9f
diff --git a/zerver/lib/upload/__init__.py b/zerver/lib/upload/__init__.py
index 35e3d7a117c..119ce917d7b 100644
--- a/zerver/lib/upload/__init__.py
+++ b/zerver/lib/upload/__init__.py
@@ -260,6 +260,17 @@ def copy_avatar(source_profile: UserProfile, target_profile: UserProfile) -> Non
def ensure_avatar_image(user_profile: UserProfile, medium: bool = False) -> None:
file_path = user_avatar_path(user_profile)
+ final_file_path = upload_backend.get_avatar_path(file_path, medium)
+
+ if settings.LOCAL_AVATARS_DIR is not None:
+ output_path = os.path.join(
+ settings.LOCAL_AVATARS_DIR,
+ final_file_path,
+ )
+
+ if os.path.isfile(output_path):
+ return
+
image_data, _ = upload_backend.get_avatar_contents(file_path)
if medium:
@@ -267,7 +278,7 @@ def ensure_avatar_image(user_profile: UserProfile, medium: bool = False) -> None
else:
resized_avatar = resize_avatar(image_data)
upload_backend.upload_single_avatar_image(
- upload_backend.get_avatar_path(file_path, medium),
+ final_file_path,
user_profile=user_profile,
image_data=resized_avatar,
content_type="image/png",
diff --git a/zerver/lib/upload/local.py b/zerver/lib/upload/local.py
index 10c3ed2ed11..44b4781fb18 100644
--- a/zerver/lib/upload/local.py
+++ b/zerver/lib/upload/local.py
@@ -126,12 +126,7 @@ class LocalUploadBackend(ZulipUploadBackend):
image_data: bytes,
content_type: Optional[str],
) -> None:
- output_path = os.path.join(
- assert_is_not_none(settings.LOCAL_AVATARS_DIR),
- file_path,
- )
- if not os.path.isfile(output_path):
- write_local_file("avatars", file_path, image_data)
+ write_local_file("avatars", file_path, image_data)
@override
def delete_avatar_image(self, path_id: str) -> None: