tusd: Support None value for MAX_WEB_DATA_IMPORT_SIZE_MB.

Adds support for `None` and defines how different values will be
used in `prod_settings_template.py`.
This commit is contained in:
Aman Agrawal
2025-04-29 11:24:57 +05:30
committed by Tim Abbott
parent 5a5660fcbf
commit b68479f623
3 changed files with 17 additions and 11 deletions

View File

@@ -442,6 +442,7 @@ class TusdPreCreateTest(ZulipTestCase):
request = self.request(key=confirmation_key)
assert settings.MAX_WEB_DATA_IMPORT_SIZE_MB is not None
max_upload_size = settings.MAX_WEB_DATA_IMPORT_SIZE_MB * 1024 * 1024
request.event.upload.size = max_upload_size + 1
result = self.client_post(

View File

@@ -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 # 1G
if 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"

View File

@@ -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