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.

uploads: Inline the one callsite of get_local_file_path.

Alex Vandiverf0f4aa66e062
diff --git a/zerver/lib/upload/local.py b/zerver/lib/upload/local.py
index 989c3088284..69ffd7b3327 100644
--- a/zerver/lib/upload/local.py
+++ b/zerver/lib/upload/local.py
@@ -68,16 +68,6 @@ def delete_local_file(type: Literal["avatars", "files"], path: str) -> bool:
return False
-def get_local_file_path(path_id: str) -> Optional[str]:
- local_path = os.path.join(assert_is_not_none(settings.LOCAL_FILES_DIR), path_id)
- assert_is_local_storage_path("files", local_path)
-
- if os.path.isfile(local_path):
- return local_path
- else:
- return None
-
-
LOCAL_FILE_ACCESS_TOKEN_SALT = "local_file_"
diff --git a/zerver/tests/test_upload.py b/zerver/tests/test_upload.py
index 89dba48cc1a..1d6b1fd7956 100644
--- a/zerver/tests/test_upload.py
+++ b/zerver/tests/test_upload.py
@@ -61,7 +61,7 @@ from zerver.lib.upload.base import (
resize_emoji,
sanitize_name,
)
-from zerver.lib.upload.local import LocalUploadBackend, get_local_file_path, write_local_file
+from zerver.lib.upload.local import LocalUploadBackend, write_local_file
from zerver.lib.upload.s3 import S3UploadBackend
from zerver.lib.users import get_api_key
from zerver.models import (
@@ -429,8 +429,8 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
+ ")"
)
message_id = self.send_stream_message(hamlet, "Denmark", body, "test")
- d3_local_path = get_local_file_path(d3_path_id)
- assert d3_local_path is not None
+ assert settings.LOCAL_FILES_DIR
+ d3_local_path = os.path.join(settings.LOCAL_FILES_DIR, d3_path_id)
self.assertTrue(os.path.exists(d3_local_path))
do_delete_messages(hamlet.realm, [Message.objects.get(id=message_id)])
diff --git a/zerver/views/upload.py b/zerver/views/upload.py
index f943b9ef643..da6a4bd02d0 100644
--- a/zerver/views/upload.py
+++ b/zerver/views/upload.py
@@ -24,8 +24,8 @@ from zerver.lib.response import json_success
from zerver.lib.upload import check_upload_within_quota, upload_message_image_from_request
from zerver.lib.upload.base import INLINE_MIME_TYPES
from zerver.lib.upload.local import (
+ assert_is_local_storage_path,
generate_unauthed_file_access_url,
- get_local_file_path,
get_local_file_path_id_from_token,
)
from zerver.lib.upload.s3 import get_signed_upload_url
@@ -96,8 +96,10 @@ def serve_s3(
def serve_local(
request: HttpRequest, path_id: str, url_only: bool, download: bool = False
) -> HttpResponseBase:
- local_path = get_local_file_path(path_id)
- if local_path is None:
+ assert settings.LOCAL_FILES_DIR is not None
+ local_path = os.path.join(settings.LOCAL_FILES_DIR, path_id)
+ assert_is_local_storage_path("files", local_path)
+ if not os.path.isfile(local_path):
return HttpResponseNotFound("<p>File not found</p>")
if url_only: