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_util: Return an `AttachmentLinkResult` instead of a tuple.

PieterCK9be5b9b8fad5
diff --git a/zerver/data_import/import_util.py b/zerver/data_import/import_util.py
index 7ff0a23ef37..f593a2ae1a5 100644
--- a/zerver/data_import/import_util.py
+++ b/zerver/data_import/import_util.py
@@ -42,6 +42,13 @@ from zproject.backends import all_default_backend_names
# stubs
ZerverFieldsT: TypeAlias = dict[str, Any]
+
+@dataclass
+class AttachmentLinkResult:
+ path_id: str
+ markdown_link: str
+
+
DATA_IMPORT_CLIENTS = {
# Match low ID clients in zerver/lib/server_initialization.py.
# This has no functional impact other than ensuring low IDs.
@@ -884,7 +891,7 @@ def get_data_file(path: str) -> Any:
def get_attachment_path_and_content(
link_name: str, filename: str, realm_id: int
-) -> tuple[str, str]:
+) -> AttachmentLinkResult:
# Should be kept in sync with its equivalent in zerver/lib/uploads in the function
# 'upload_message_attachment'
s3_path = "/".join(
@@ -898,4 +905,4 @@ def get_attachment_path_and_content(
attachment_path = f"/user_uploads/{s3_path}"
content = f"[{link_name}]({attachment_path})"
- return s3_path, content
+ return AttachmentLinkResult(path_id=s3_path, markdown_link=content)
diff --git a/zerver/data_import/slack.py b/zerver/data_import/slack.py
index a4b2fbaafbc..d7d0fa04ee9 100644
--- a/zerver/data_import/slack.py
+++ b/zerver/data_import/slack.py
@@ -1320,10 +1320,10 @@ def process_message_files(
has_link = True
has_image = "image" in fileinfo["mimetype"]
- s3_path, content_for_link = get_attachment_path_and_content(
+ attachment_data = get_attachment_path_and_content(
link_name=fileinfo["title"], filename=fileinfo["name"], realm_id=realm_id
)
- markdown_links.append(content_for_link)
+ markdown_links.append(attachment_data.markdown_link)
uploads_list.append(
UploadRecordData(
@@ -1332,7 +1332,7 @@ def process_message_files(
# Save Slack's URL here, which is used later while processing
path=fileinfo["url_private"],
realm_id=realm_id,
- s3_path=s3_path,
+ s3_path=attachment_data.path_id,
size=fileinfo["size"],
user_profile_id=slack_user_id_to_zulip_user_id[slack_user_id],
)
@@ -1343,7 +1343,7 @@ def process_message_files(
{message_id},
slack_user_id_to_zulip_user_id[slack_user_id],
fileinfo,
- s3_path,
+ attachment_data.path_id,
zerver_attachment,
)
else: