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.

upload: Rename upload_message_file to use word "attachment".

Alex Vandiver567d1d54e7c0
diff --git a/zerver/data_import/slack.py b/zerver/data_import/slack.py
index 304018b8f02..1643c85bbfb 100644
--- a/zerver/data_import/slack.py
+++ b/zerver/data_import/slack.py
@@ -1100,7 +1100,7 @@ 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_file'
+ # 'upload_message_attachment'
s3_path = "/".join(
[
str(realm_id),
diff --git a/zerver/lib/email_mirror.py b/zerver/lib/email_mirror.py
index 6c6ba5974e1..2b8bcef5a87 100644
--- a/zerver/lib/email_mirror.py
+++ b/zerver/lib/email_mirror.py
@@ -26,7 +26,7 @@ from zerver.lib.queue import queue_json_publish
from zerver.lib.rate_limiter import RateLimitedObject
from zerver.lib.send_email import FromAddress
from zerver.lib.string_validation import is_character_printable
-from zerver.lib.upload import upload_message_file
+from zerver.lib.upload import upload_message_attachment
from zerver.models import (
Message,
MissedMessageEmailAddress,
@@ -337,7 +337,7 @@ def extract_and_upload_attachments(message: EmailMessage, realm: Realm, sender:
if filename:
attachment = part.get_payload(decode=True)
if isinstance(attachment, bytes):
- s3_url = upload_message_file(
+ s3_url = upload_message_attachment(
filename,
len(attachment),
content_type,
diff --git a/zerver/lib/upload/__init__.py b/zerver/lib/upload/__init__.py
index 6b690602876..ab1674a868b 100644
--- a/zerver/lib/upload/__init__.py
+++ b/zerver/lib/upload/__init__.py
@@ -103,7 +103,7 @@ def upload_emoji_image(
return upload_backend.upload_emoji_image(emoji_file, emoji_file_name, user_profile)
-def upload_message_file(
+def upload_message_attachment(
uploaded_file_name: str,
uploaded_file_size: int,
content_type: Optional[str],
@@ -111,7 +111,7 @@ def upload_message_file(
user_profile: UserProfile,
target_realm: Optional[Realm] = None,
) -> str:
- return upload_backend.upload_message_file(
+ return upload_backend.upload_message_attachment(
uploaded_file_name,
uploaded_file_size,
content_type,
@@ -140,7 +140,7 @@ def upload_message_image_from_request(
user_file: UploadedFile, user_profile: UserProfile, user_file_size: int
) -> str:
uploaded_file_name, content_type = get_file_info(user_file)
- return upload_message_file(
+ return upload_message_attachment(
uploaded_file_name, user_file_size, content_type, user_file.read(), user_profile
)
diff --git a/zerver/lib/upload/base.py b/zerver/lib/upload/base.py
index 3eb07e230c2..eea053035f9 100644
--- a/zerver/lib/upload/base.py
+++ b/zerver/lib/upload/base.py
@@ -191,7 +191,7 @@ class ZulipUploadBackend:
def generate_message_upload_path(self, realm_id: str, uploaded_file_name: str) -> str:
raise NotImplementedError
- def upload_message_file(
+ def upload_message_attachment(
self,
uploaded_file_name: str,
uploaded_file_size: int,
diff --git a/zerver/lib/upload/local.py b/zerver/lib/upload/local.py
index 6520e9e4907..0cba498d24c 100644
--- a/zerver/lib/upload/local.py
+++ b/zerver/lib/upload/local.py
@@ -78,7 +78,7 @@ class LocalUploadBackend(ZulipUploadBackend):
]
)
- def upload_message_file(
+ def upload_message_attachment(
self,
uploaded_file_name: str,
uploaded_file_size: int,
diff --git a/zerver/lib/upload/s3.py b/zerver/lib/upload/s3.py
index 19b9d90cfd5..7818d22be80 100644
--- a/zerver/lib/upload/s3.py
+++ b/zerver/lib/upload/s3.py
@@ -203,7 +203,7 @@ class S3UploadBackend(ZulipUploadBackend):
]
)
- def upload_message_file(
+ def upload_message_attachment(
self,
uploaded_file_name: str,
uploaded_file_size: int,
diff --git a/zerver/openapi/curl_param_value_generators.py b/zerver/openapi/curl_param_value_generators.py
index 8e188c9155b..0342057b441 100644
--- a/zerver/openapi/curl_param_value_generators.py
+++ b/zerver/openapi/curl_param_value_generators.py
@@ -18,7 +18,7 @@ from zerver.actions.realm_playgrounds import do_add_realm_playground
from zerver.lib.events import do_events_register
from zerver.lib.initial_password import initial_password
from zerver.lib.test_classes import ZulipTestCase
-from zerver.lib.upload import upload_message_file
+from zerver.lib.upload import upload_message_attachment
from zerver.lib.users import get_api_key
from zerver.models import Client, Message, UserGroup, UserPresence, get_realm, get_user
@@ -345,7 +345,9 @@ def deactivate_own_user() -> Dict[str, object]:
@openapi_param_value_generator(["/attachments/{attachment_id}:delete"])
def remove_attachment() -> Dict[str, object]:
user_profile = helpers.example_user("iago")
- url = upload_message_file("dummy.txt", len(b"zulip!"), "text/plain", b"zulip!", user_profile)
+ url = upload_message_attachment(
+ "dummy.txt", len(b"zulip!"), "text/plain", b"zulip!", user_profile
+ )
attachment_id = url.replace("/user_uploads/", "").split("/")[0]
return {"attachment_id": attachment_id}
diff --git a/zerver/tests/test_email_mirror.py b/zerver/tests/test_email_mirror.py
index 97eb20953c4..7e96ded8328 100644
--- a/zerver/tests/test_email_mirror.py
+++ b/zerver/tests/test_email_mirror.py
@@ -601,11 +601,11 @@ class TestEmailMirrorMessagesWithAttachments(ZulipTestCase):
incoming_valid_message["Reply-to"] = self.example_email("othello")
with mock.patch(
- "zerver.lib.email_mirror.upload_message_file",
+ "zerver.lib.email_mirror.upload_message_attachment",
return_value="https://test_url",
- ) as upload_message_file:
+ ) as upload_message_attachment:
process_message(incoming_valid_message)
- upload_message_file.assert_called_with(
+ upload_message_attachment.assert_called_with(
"image.png",
len(image_bytes),
"image/png",
@@ -728,11 +728,11 @@ class TestEmailMirrorMessagesWithAttachments(ZulipTestCase):
incoming_valid_message["Reply-to"] = self.example_email("othello")
with mock.patch(
- "zerver.lib.email_mirror.upload_message_file",
+ "zerver.lib.email_mirror.upload_message_attachment",
return_value="https://test_url",
- ) as upload_message_file:
+ ) as upload_message_attachment:
process_message(incoming_valid_message)
- upload_message_file.assert_called_with(
+ upload_message_attachment.assert_called_with(
utf8_filename,
len(image_bytes),
"image/png",
@@ -775,11 +775,11 @@ class TestEmailMirrorMessagesWithAttachments(ZulipTestCase):
incoming_valid_message["Reply-to"] = self.example_email("othello")
with mock.patch(
- "zerver.lib.email_mirror.upload_message_file",
+ "zerver.lib.email_mirror.upload_message_attachment",
return_value="https://test_url",
- ) as upload_message_file:
+ ) as upload_message_attachment:
process_message(incoming_valid_message)
- upload_message_file.assert_called_with(
+ upload_message_attachment.assert_called_with(
"image.png",
len(image_bytes),
"image/png",
diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.py
index 44e9901578a..6c0103b44df 100644
--- a/zerver/tests/test_import_export.py
+++ b/zerver/tests/test_import_export.py
@@ -48,7 +48,7 @@ from zerver.lib.test_helpers import (
read_test_image_file,
use_s3_backend,
)
-from zerver.lib.upload import claim_attachment, upload_avatar_image, upload_message_file
+from zerver.lib.upload import claim_attachment, upload_avatar_image, upload_message_attachment
from zerver.lib.user_topics import add_topic_mute
from zerver.lib.utils import assert_is_not_none
from zerver.models import (
@@ -154,7 +154,7 @@ class ExportFile(ZulipTestCase):
self, user_profile: UserProfile, *, emoji_name: str = "whatever"
) -> None:
message = most_recent_message(user_profile)
- url = upload_message_file(
+ url = upload_message_attachment(
"dummy.txt", len(b"zulip!"), "text/plain", b"zulip!", user_profile
)
attachment_path_id = url.replace("/user_uploads/", "")
@@ -355,7 +355,7 @@ class RealmImportExportTest(ExportFile):
# We create an attachment tied to a personal message. That means it shouldn't be
# included in a public export, as it's private data.
personal_message_id = self.send_personal_message(user_profile, self.example_user("othello"))
- url = upload_message_file(
+ url = upload_message_attachment(
"dummy.txt", len(b"zulip!"), "text/plain", b"zulip!", user_profile
)
attachment_path_id = url.replace("/user_uploads/", "")
diff --git a/zerver/tests/test_transfer.py b/zerver/tests/test_transfer.py
index b7878e26c66..325cc62754b 100644
--- a/zerver/tests/test_transfer.py
+++ b/zerver/tests/test_transfer.py
@@ -19,7 +19,7 @@ from zerver.lib.transfer import (
transfer_message_files_to_s3,
transfer_uploads_to_s3,
)
-from zerver.lib.upload import upload_message_file
+from zerver.lib.upload import upload_message_attachment
from zerver.lib.upload.base import resize_emoji
from zerver.models import Attachment, RealmEmoji
@@ -67,8 +67,8 @@ class TransferUploadsToS3Test(ZulipTestCase):
hamlet = self.example_user("hamlet")
othello = self.example_user("othello")
- upload_message_file("dummy1.txt", len(b"zulip1!"), "text/plain", b"zulip1!", hamlet)
- upload_message_file("dummy2.txt", len(b"zulip2!"), "text/plain", b"zulip2!", othello)
+ upload_message_attachment("dummy1.txt", len(b"zulip1!"), "text/plain", b"zulip1!", hamlet)
+ upload_message_attachment("dummy2.txt", len(b"zulip2!"), "text/plain", b"zulip2!", othello)
with self.assertLogs(level="INFO"):
transfer_message_files_to_s3(1)
diff --git a/zerver/tests/test_upload.py b/zerver/tests/test_upload.py
index d8e39ab9b28..13cd08de274 100644
--- a/zerver/tests/test_upload.py
+++ b/zerver/tests/test_upload.py
@@ -50,7 +50,7 @@ from zerver.lib.upload import (
delete_message_image,
upload_emoji_image,
upload_export_tarball,
- upload_message_file,
+ upload_message_attachment,
)
from zerver.lib.upload.base import (
DEFAULT_AVATAR_SIZE,
@@ -1844,9 +1844,9 @@ class RealmNightLogoTest(RealmLogoTest):
class LocalStorageTest(UploadSerializeMixin, ZulipTestCase):
- def test_file_upload_local(self) -> None:
+ def test_upload_message_attachment_local(self) -> None:
user_profile = self.example_user("hamlet")
- uri = upload_message_file(
+ uri = upload_message_attachment(
"dummy.txt", len(b"zulip!"), "text/plain", b"zulip!", user_profile
)
@@ -1861,7 +1861,7 @@ class LocalStorageTest(UploadSerializeMixin, ZulipTestCase):
uploaded_file = Attachment.objects.get(owner=user_profile, path_id=path_id)
self.assert_length(b"zulip!", uploaded_file.size)
- def test_file_upload_local_cross_realm_path(self) -> None:
+ def test_upload_message_attachment_local_cross_realm_path(self) -> None:
"""
Verifies that the path of a file uploaded by a cross-realm bot to another
realm is correct.
@@ -1872,7 +1872,7 @@ class LocalStorageTest(UploadSerializeMixin, ZulipTestCase):
user_profile = get_system_bot(settings.EMAIL_GATEWAY_BOT, internal_realm.id)
self.assertEqual(user_profile.realm, internal_realm)
- uri = upload_message_file(
+ uri = upload_message_attachment(
"dummy.txt", len(b"zulip!"), "text/plain", b"zulip!", user_profile, zulip_realm
)
# Ensure the correct realm id of the target realm is used instead of the bot's realm.
@@ -2039,11 +2039,11 @@ class LocalStorageTest(UploadSerializeMixin, ZulipTestCase):
class S3Test(ZulipTestCase):
@use_s3_backend
- def test_file_upload_s3(self) -> None:
+ def test_upload_message_attachment_s3(self) -> None:
bucket = create_s3_buckets(settings.S3_AUTH_UPLOADS_BUCKET)[0]
user_profile = self.example_user("hamlet")
- uri = upload_message_file(
+ uri = upload_message_attachment(
"dummy.txt", len(b"zulip!"), "text/plain", b"zulip!", user_profile
)
@@ -2061,7 +2061,7 @@ class S3Test(ZulipTestCase):
self.send_stream_message(self.example_user("hamlet"), "Denmark", body, "test")
@use_s3_backend
- def test_file_upload_s3_cross_realm_path(self) -> None:
+ def test_upload_message_attachment_s3_cross_realm_path(self) -> None:
"""
Verifies that the path of a file uploaded by a cross-realm bot to another
realm is correct.
@@ -2073,18 +2073,18 @@ class S3Test(ZulipTestCase):
user_profile = get_system_bot(settings.EMAIL_GATEWAY_BOT, internal_realm.id)
self.assertEqual(user_profile.realm, internal_realm)
- uri = upload_message_file(
+ uri = upload_message_attachment(
"dummy.txt", len(b"zulip!"), "text/plain", b"zulip!", user_profile, zulip_realm
)
# Ensure the correct realm id of the target realm is used instead of the bot's realm.
self.assertTrue(uri.startswith(f"/user_uploads/{zulip_realm.id}/"))
@use_s3_backend
- def test_file_upload_s3_with_undefined_content_type(self) -> None:
+ def test_upload_message_attachment_s3_with_undefined_content_type(self) -> None:
bucket = create_s3_buckets(settings.S3_AUTH_UPLOADS_BUCKET)[0]
user_profile = self.example_user("hamlet")
- uri = upload_message_file("dummy.txt", len(b"zulip!"), None, b"zulip!", user_profile)
+ uri = upload_message_attachment("dummy.txt", len(b"zulip!"), None, b"zulip!", user_profile)
path_id = re.sub("/user_uploads/", "", uri)
self.assertEqual(b"zulip!", bucket.Object(path_id).get()["Body"].read())
@@ -2096,7 +2096,7 @@ class S3Test(ZulipTestCase):
create_s3_buckets(settings.S3_AUTH_UPLOADS_BUCKET)
user_profile = self.example_user("hamlet")
- uri = upload_message_file(
+ uri = upload_message_attachment(
"dummy.txt", len(b"zulip!"), "text/plain", b"zulip!", user_profile
)
@@ -2115,7 +2115,7 @@ class S3Test(ZulipTestCase):
)
@use_s3_backend
- def test_file_upload_authed(self) -> None:
+ def test_user_uploads_authed(self) -> None:
"""
A call to /json/user_uploads should return a uri and actually create an object.
"""
@@ -2507,14 +2507,14 @@ class UploadSpaceTests(UploadSerializeMixin, ZulipTestCase):
self.assertEqual(0, cache_get(get_realm_used_upload_space_cache_key(self.realm))[0])
data = b"zulip!"
- upload_message_file("dummy.txt", len(data), "text/plain", data, self.user_profile)
+ upload_message_attachment("dummy.txt", len(data), "text/plain", data, self.user_profile)
# notify_attachment_update function calls currently_used_upload_space_bytes which
# updates the cache.
self.assert_length(data, cache_get(get_realm_used_upload_space_cache_key(self.realm))[0])
self.assert_length(data, self.realm.currently_used_upload_space_bytes())
data2 = b"more-data!"
- upload_message_file("dummy2.txt", len(data2), "text/plain", data2, self.user_profile)
+ upload_message_attachment("dummy2.txt", len(data2), "text/plain", data2, self.user_profile)
self.assertEqual(
len(data) + len(data2), cache_get(get_realm_used_upload_space_cache_key(self.realm))[0]
)