Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
import/mattermost: Don't flag posts whose attachments are all missing.
PieterCK079cd666b311
diff --git a/zerver/data_import/mattermost.py b/zerver/data_import/mattermost.pyindex 14321b84385..1269f297124 100644--- a/zerver/data_import/mattermost.py+++ b/zerver/data_import/mattermost.py@@ -581,9 +581,6 @@ def process_raw_message_batch(has_image = Falsehas_link = Falseif "attachments" in raw_message:- has_attachment = True- has_link = True-attachment_markdown, has_image = process_message_attachments(attachments=raw_message["attachments"],realm_id=realm_id,@@ -595,9 +592,14 @@ def process_raw_message_batch(output_dir=output_dir,)- if content:- content += "\n\n"- content += attachment_markdown+ # Attachments whose files are missing from the export are+ # skipped, so there may be none left to link.+ if attachment_markdown:+ has_attachment = True+ has_link = True+ if content:+ content += "\n\n"+ content += attachment_markdowntopic_name = "imported from mattermost"diff --git a/zerver/tests/test_mattermost_importer.py b/zerver/tests/test_mattermost_importer.pyindex 4dd3cbe0c45..866d2122624 100644--- a/zerver/tests/test_mattermost_importer.py+++ b/zerver/tests/test_mattermost_importer.py@@ -1,4 +1,5 @@import filecmp+import globimport jsonimport osimport shutil@@ -1422,6 +1423,37 @@ class MattermostV1110ImportTest(MattermostImportTestBase):exported_bot_users = [user for user in mattermost_data["user"] if user.get("is_bot")]self.assert_length(exported_bot_users, 3)+ def test_converted_messages_only_flag_exported_attachments(self) -> None:+ output_dir = make_export_output_dir()+ with self.settings(EXTERNAL_HOST="zulip.example.com"), self.assertLogs(level="INFO"):+ do_convert_data(+ mattermost_data_dir=self.fixture_file_name("", self.FIXTURE_DIR),+ output_dir=output_dir,+ masking_content=False,+ )+ team_output_dir = self.team_output_dir(output_dir, self.TEAM)++ attachment_records = self.read_file(team_output_dir, "attachment.json")+ attachment_message_ids = {+ message_id+ for attachment in attachment_records["zerver_attachment"]+ for message_id in attachment["messages"]+ }+ converted_messages = []+ for messages_file in glob.glob(os.path.join(team_output_dir, "messages-*.json")):+ message_records = self.read_file(team_output_dir, os.path.basename(messages_file))+ converted_messages.extend(message_records["zerver_message"])+ # The export has a post whose only attachment file is missing,+ # which shouldn't be flagged.+ self.assertSetEqual(+ {message["id"] for message in converted_messages if message["has_attachment"]},+ attachment_message_ids,+ )+ self.assertSetEqual(+ {message["id"] for message in converted_messages if message["has_link"]},+ attachment_message_ids,+ )+def test_e2e_export_data_v11_1_0(self) -> None:with self.settings(EXTERNAL_HOST="zulip.example.com"):conversion_result = self.run_convert_and_import(