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.

data_import: Refactor `get_attachment_path_and_content` parameter.

PieterCK463204f3cf69
diff --git a/zerver/data_import/import_util.py b/zerver/data_import/import_util.py
index ee6a98c82bc..7ff0a23ef37 100644
--- a/zerver/data_import/import_util.py
+++ b/zerver/data_import/import_util.py
@@ -882,7 +882,9 @@ def get_data_file(path: str) -> Any:
return data
-def get_attachment_path_and_content(fileinfo: ZerverFieldsT, realm_id: int) -> tuple[str, str]:
+def get_attachment_path_and_content(
+ link_name: str, filename: str, realm_id: int
+) -> tuple[str, str]:
# Should be kept in sync with its equivalent in zerver/lib/uploads in the function
# 'upload_message_attachment'
s3_path = "/".join(
@@ -890,10 +892,10 @@ def get_attachment_path_and_content(fileinfo: ZerverFieldsT, realm_id: int) -> t
str(realm_id),
format(random.randint(0, 255), "x"),
secrets.token_urlsafe(18),
- sanitize_name(fileinfo["name"]),
+ sanitize_name(filename),
]
)
attachment_path = f"/user_uploads/{s3_path}"
- content = "[{}]({})".format(fileinfo["title"], attachment_path)
+ content = f"[{link_name}]({attachment_path})"
return s3_path, content
diff --git a/zerver/data_import/slack.py b/zerver/data_import/slack.py
index fd1bd7a1874..a4b2fbaafbc 100644
--- a/zerver/data_import/slack.py
+++ b/zerver/data_import/slack.py
@@ -1320,7 +1320,9 @@ def process_message_files(
has_link = True
has_image = "image" in fileinfo["mimetype"]
- s3_path, content_for_link = get_attachment_path_and_content(fileinfo, realm_id)
+ s3_path, content_for_link = get_attachment_path_and_content(
+ link_name=fileinfo["title"], filename=fileinfo["name"], realm_id=realm_id
+ )
markdown_links.append(content_for_link)
uploads_list.append(