Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
data_import: Move `get_attachment_path_and_content` to import util.
PieterCK21a6546ef012
diff --git a/zerver/data_import/import_util.py b/zerver/data_import/import_util.pyindex 0f3a4c20800..ee6a98c82bc 100644--- a/zerver/data_import/import_util.py+++ b/zerver/data_import/import_util.py@@ -1,6 +1,7 @@import loggingimport osimport random+import secretsimport shutilimport subprocessfrom collections import defaultdict@@ -24,6 +25,7 @@ from zerver.lib.parallel import run_parallelfrom zerver.lib.partial import partialfrom zerver.lib.stream_color import STREAM_ASSIGNMENT_COLORS as STREAM_COLORSfrom zerver.lib.thumbnail import THUMBNAIL_ACCEPT_IMAGE_TYPES, BadImageError+from zerver.lib.upload import sanitize_namefrom zerver.models import (Attachment,DirectMessageGroup,@@ -878,3 +880,20 @@ def get_data_file(path: str) -> Any:with open(path, "rb") as fp:data = orjson.loads(fp.read())return data+++def get_attachment_path_and_content(fileinfo: ZerverFieldsT, 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(+ [+ str(realm_id),+ format(random.randint(0, 255), "x"),+ secrets.token_urlsafe(18),+ sanitize_name(fileinfo["name"]),+ ]+ )+ attachment_path = f"/user_uploads/{s3_path}"+ content = "[{}]({})".format(fileinfo["title"], attachment_path)++ return s3_path, contentdiff --git a/zerver/data_import/slack.py b/zerver/data_import/slack.pyindex b757d62f03d..fd1bd7a1874 100644--- a/zerver/data_import/slack.py+++ b/zerver/data_import/slack.py@@ -2,9 +2,7 @@ import itertoolsimport loggingimport osimport posixpath-import randomimport re-import secretsimport shutilimport timeimport zipfile@@ -38,6 +36,7 @@ from zerver.data_import.import_util import (build_usermessages,build_zerver_realm,create_converted_data_files,+ get_attachment_path_and_content,get_data_file,long_term_idle_helper,make_subscriber_map,@@ -59,7 +58,6 @@ from zerver.lib.message import truncate_contentfrom zerver.lib.mime_types import guess_typefrom zerver.lib.storage import static_pathfrom zerver.lib.thumbnail import THUMBNAIL_ACCEPT_IMAGE_TYPES, resize_realm_icon-from zerver.lib.upload import sanitize_namefrom zerver.models import (CustomProfileField,CustomProfileFieldValue,@@ -1366,23 +1364,6 @@ def process_message_files()-def get_attachment_path_and_content(fileinfo: ZerverFieldsT, 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(- [- str(realm_id),- format(random.randint(0, 255), "x"),- secrets.token_urlsafe(18),- sanitize_name(fileinfo["name"]),- ]- )- attachment_path = f"/user_uploads/{s3_path}"- content = "[{}]({})".format(fileinfo["title"], attachment_path)-- return s3_path, content--def build_reactions(reaction_list: list[ZerverFieldsT],reactions: list[ZerverFieldsT],