Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
tusd: Support None value for `MAX_WEB_DATA_IMPORT_SIZE_MB`.
Aman Agrawalb68479f623f0
diff --git a/zerver/tests/test_tusd.py b/zerver/tests/test_tusd.pyindex 6bcf2463cd5..df6706369bb 100644--- a/zerver/tests/test_tusd.py+++ b/zerver/tests/test_tusd.py@@ -442,6 +442,7 @@ class TusdPreCreateTest(ZulipTestCase):request = self.request(key=confirmation_key)+ assert settings.MAX_WEB_DATA_IMPORT_SIZE_MB is not Nonemax_upload_size = settings.MAX_WEB_DATA_IMPORT_SIZE_MB * 1024 * 1024request.event.upload.size = max_upload_size + 1result = self.client_post(diff --git a/zerver/views/tusd.py b/zerver/views/tusd.pyindex abb73b4a36b..bef73c565c4 100644--- a/zerver/views/tusd.py+++ b/zerver/views/tusd.py@@ -257,16 +257,18 @@ def authenticate_user(request: HttpRequest) -> UserProfile | AnonymousUser:def handle_preregistration_pre_create_hook(request: HttpRequest, preregistration_realm: PreregistrationRealm, data: TusUpload) -> HttpResponse:- max_upload_size = settings.MAX_WEB_DATA_IMPORT_SIZE_MB * 1024 * 1024 # 1Gif data.size_is_deferred or data.size is None:return reject_upload("SizeIsDeferred is not supported", 411)- if data.size > max_upload_size:- return reject_upload(- _(- "Uploaded file exceeds the maximum file size for imports ({max_file_size} MiB)."- ).format(max_file_size=settings.MAX_WEB_DATA_IMPORT_SIZE_MB),- 413,- )++ if settings.MAX_WEB_DATA_IMPORT_SIZE_MB is not None:+ max_upload_size = settings.MAX_WEB_DATA_IMPORT_SIZE_MB * 1024 * 1024 # 1G+ if data.size > max_upload_size:+ return reject_upload(+ _(+ "Uploaded file exceeds the maximum file size for imports ({max_file_size} MiB)."+ ).format(max_file_size=settings.MAX_WEB_DATA_IMPORT_SIZE_MB),+ 413,+ )filename = f"import/{preregistration_realm.id}/slack.zip"diff --git a/zproject/default_settings.py b/zproject/default_settings.pyindex 543aab96def..a099b8f431e 100644--- a/zproject/default_settings.py+++ b/zproject/default_settings.py@@ -698,9 +698,12 @@ CUSTOM_AUTHENTICATION_WRAPPER_FUNCTION: Callable[..., Any] | None = None# notification.RESOLVE_TOPIC_UNDO_GRACE_PERIOD_SECONDS = 60-# For realm imports during registration, maximum size of file-# that can be uploaded.-MAX_WEB_DATA_IMPORT_SIZE_MB = 1024+# Maximum allowed size of uploaded file for realm import, in megabytes.+# 0 disables import; None means no limit.+#+# Note that this is a limit for the size of the uploaded export+# itself, not any additional files that may be imported as well.+MAX_WEB_DATA_IMPORT_SIZE_MB: int | None = 1024# Minimum and maximum permitted number of days before full data# deletion when deactivating an organization. A nonzero minimum helps