Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
user export: Show less info for recipients.
Steve Howell9a39ca217f4a
diff --git a/zerver/lib/export.py b/zerver/lib/export.pyindex c2189dd32ca..3c0786f73b2 100644--- a/zerver/lib/export.py+++ b/zerver/lib/export.py@@ -28,6 +28,7 @@ from typing_extensions import TypedDictimport zerver.lib.uploadfrom analytics.models import RealmCount, StreamCount, UserCountfrom scripts.lib.zulip_tools import overwrite_symlink+from zerver.decorator import cachifyfrom zerver.lib.avatar_hash import user_avatar_path_from_idsfrom zerver.lib.pysa import mark_sanitizedfrom zerver.lib.upload import get_bucket@@ -66,7 +67,6 @@ from zerver.models import (UserProfile,UserStatus,UserTopic,- get_display_recipient,get_realm,get_system_bot,get_user_profile_by_id,@@ -2096,6 +2096,23 @@ def chunkify(lst: List[int], chunk_size: int) -> List[List[int]]:def export_messages_single_user(user_profile: UserProfile, *, output_dir: Path, reaction_message_ids: Set[int]) -> None:+ @cachify+ def get_recipient(recipient_id: int) -> str:+ recipient = Recipient.objects.get(id=recipient_id)++ if recipient.type == Recipient.STREAM:+ stream = Stream.objects.values("name").get(id=recipient.type_id)+ return stream["name"]++ user_names = (+ UserProfile.objects.filter(+ subscription__recipient_id=recipient.id,+ )+ .order_by("full_name")+ .values_list("full_name", flat=True)+ )++ return ", ".join(user_names)messages_from_me = Message.objects.filter(sender=user_profile)@@ -2130,7 +2147,7 @@ def export_messages_single_user(item["flags_mask"] = user_message.flags.mask# Add a few nice, human-readable detailsitem["sending_client_name"] = user_message.message.sending_client.name- item["display_recipient"] = get_display_recipient(user_message.message.recipient)+ item["recipient_name"] = get_recipient(user_message.message.recipient_id)message_chunk.append(item)message_filename = os.path.join(output_dir, f"messages-{dump_file_id:06}.json")diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.pyindex f90b35b116c..d138be5e3cd 100644--- a/zerver/tests/test_import_export.py+++ b/zerver/tests/test_import_export.py@@ -707,18 +707,23 @@ class ImportExportTest(ZulipTestCase):exported_messages_recipient = self.get_set(messages["zerver_message"], "recipient")self.assertIn(list(exported_messages_recipient)[0], exported_recipient_id)- excerpt = [(rec["id"], rec["content"]) for rec in messages["zerver_message"][-8:]]+ huddle_name = "Cordelia, Lear's daughter, King Hamlet, Othello, the Moor of Venice"++ excerpt = [+ (rec["id"], rec["content"], rec["recipient_name"])+ for rec in messages["zerver_message"][-8:]+ ]self.assertEqual(excerpt,[- (smile_message_id, "SMILE!"),- (hi_stream_message_id, "hi stream"),- (hi_hamlet_message_id, "hi hamlet"),- (hi_peeps_message_id, "hi peeps"),- (bye_peeps_message_id, "bye peeps"),- (bye_hamlet_message_id, "bye hamlet"),- (hi_myself_message_id, "hi myself"),- (bye_stream_message_id, "bye stream"),+ (smile_message_id, "SMILE!", "Denmark"),+ (hi_stream_message_id, "hi stream", "Denmark"),+ (hi_hamlet_message_id, "hi hamlet", hamlet.full_name),+ (hi_peeps_message_id, "hi peeps", huddle_name),+ (bye_peeps_message_id, "bye peeps", huddle_name),+ (bye_hamlet_message_id, "bye hamlet", hamlet.full_name),+ (hi_myself_message_id, "hi myself", cordelia.full_name),+ (bye_stream_message_id, "bye stream", "Denmark"),],)