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.

import: Fix missing avatar thumbnails.

Mateusz Mandera624558ffb226
diff --git a/zerver/lib/import_realm.py b/zerver/lib/import_realm.py
index c724983c591..e762a203753 100644
--- a/zerver/lib/import_realm.py
+++ b/zerver/lib/import_realm.py
@@ -928,9 +928,8 @@ def process_avatars(record: dict[str, Any]) -> None:
# same realm ID from a previous iteration).
os.remove(medium_file_path)
try:
+ ensure_avatar_image(user_profile=user_profile)
ensure_avatar_image(user_profile=user_profile, medium=True)
- if record.get("importer_should_thumbnail"):
- ensure_avatar_image(user_profile=user_profile)
except BadImageError:
logging.warning(
"Could not thumbnail avatar image for user %s; ignoring",
diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.py
index feb42ffc75a..8b487005925 100644
--- a/zerver/tests/test_import_export.py
+++ b/zerver/tests/test_import_export.py
@@ -2616,11 +2616,20 @@ class RealmImportExportTest(ExportFile):
# Test avatars
user_profile = UserProfile.objects.get(full_name=user.full_name, realm=imported_realm)
- avatar_path_id = user_avatar_path(user_profile) + ".original"
- original_image_key = avatar_bucket.Object(avatar_path_id)
- self.assertEqual(original_image_key.key, avatar_path_id)
- image_data = avatar_bucket.Object(avatar_path_id).get()["Body"].read()
+ avatar_path_id_base = user_avatar_path(user_profile)
+ avatar_path_id_original = avatar_path_id_base + ".original"
+ original_image_key = avatar_bucket.Object(avatar_path_id_original)
+ self.assertEqual(original_image_key.key, avatar_path_id_original)
+ image_data = avatar_bucket.Object(avatar_path_id_original).get()["Body"].read()
self.assertEqual(image_data, test_image_data)
+ # Ensure we've also generated the expected thumbnails.
+ avatar_path_id_thumbnail = avatar_path_id_base + "-medium.png"
+ avatar_path_id_medium_thumbnail = avatar_path_id_base + ".png"
+ for path_id in [avatar_path_id_thumbnail, avatar_path_id_medium_thumbnail]:
+ image_key = avatar_bucket.Object(path_id)
+ self.assertEqual(image_key.key, path_id)
+ image_get_response = avatar_bucket.Object(path_id).get()
+ self.assertEqual(image_get_response["ResponseMetadata"]["HTTPStatusCode"], 200)
# Test realm icon and logo
upload_path = upload.upload_backend.realm_avatar_and_logo_path(imported_realm)