From 0c2b25cab3cd3337111750f67fcef95ae73bc7ee Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Fri, 8 May 2020 10:27:19 +0530 Subject: [PATCH] home/page_params: Add suffix `_mib` to clarify the size units. The docs say "megabytes" or "MB", but client software needs to know the actual meaning, which is in mebibytes. --- frontend_tests/node_tests/compose.js | 2 +- frontend_tests/node_tests/upload.js | 4 +-- static/js/avatar.js | 2 +- static/js/message_edit.js | 2 +- static/js/upload.js | 4 +-- templates/zerver/app/compose.html | 2 +- templates/zerver/app/settings_overlay.html | 2 +- zerver/tests/test_home.py | 4 +-- zerver/views/home.py | 40 +++++++++++----------- 9 files changed, 31 insertions(+), 31 deletions(-) diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.js index f183d7e2a4..e0c4e504a4 100644 --- a/frontend_tests/node_tests/compose.js +++ b/frontend_tests/node_tests/compose.js @@ -922,7 +922,7 @@ run_test('initialize', () => { global.document = 'document-stub'; global.csrf_token = 'fake-csrf-token'; - page_params.max_file_upload_size = 512; + page_params.max_file_upload_size_mib = 512; let setup_upload_called = false; let uppy_cancel_all_called = false; diff --git a/frontend_tests/node_tests/upload.js b/frontend_tests/node_tests/upload.js index 738d59cf84..08cb90629d 100644 --- a/frontend_tests/node_tests/upload.js +++ b/frontend_tests/node_tests/upload.js @@ -176,7 +176,7 @@ run_test('upload_files', () => { upload.upload_files(uppy, config, []); assert.equal($("#compose-send-button").attr("disabled"), false); - page_params.max_file_upload_size = 0; + page_params.max_file_upload_size_mib = 0; let show_error_message_called = false; upload.show_error_message = (config, message) => { show_error_message_called = true; @@ -186,7 +186,7 @@ run_test('upload_files', () => { upload.upload_files(uppy, config, files); assert(show_error_message_called); - page_params.max_file_upload_size = 25; + page_params.max_file_upload_size_mib = 25; let on_click_close_button_callback; $(".compose-send-status-close").one = (event, callback) => { assert.equal(event, "click"); diff --git a/static/js/avatar.js b/static/js/avatar.js index 3efc2f678d..de577cd950 100644 --- a/static/js/avatar.js +++ b/static/js/avatar.js @@ -74,7 +74,7 @@ exports.build_user_avatar_widget = function (upload_function) { $("#user_avatar_file_input_error").expectOne(), $("#user-settings-avatar").expectOne(), upload_function, - page_params.max_avatar_file_size + page_params.max_avatar_file_size_mib ); } }; diff --git a/static/js/message_edit.js b/static/js/message_edit.js index 42e6357830..e092919848 100644 --- a/static/js/message_edit.js +++ b/static/js/message_edit.js @@ -254,7 +254,7 @@ function edit_message(row, raw_content) { const editability = get_editability(message, seconds_left_buffer); const is_editable = editability === exports.editability_types.TOPIC_ONLY || editability === exports.editability_types.FULL; - const max_file_upload_size = page_params.max_file_upload_size; + const max_file_upload_size = page_params.max_file_upload_size_mib; let file_upload_enabled = false; if (max_file_upload_size > 0) { diff --git a/static/js/upload.js b/static/js/upload.js index 2d16db96f2..b86d9628b6 100644 --- a/static/js/upload.js +++ b/static/js/upload.js @@ -97,7 +97,7 @@ exports.upload_files = function (uppy, config, files) { if (files.length === 0) { return; } - if (page_params.max_file_upload_size === 0) { + if (page_params.max_file_upload_size_mib === 0) { exports.show_error_message(config, i18n.t('File and image uploads have been disabled for this organization.')); return; } @@ -138,7 +138,7 @@ exports.setup_upload = function (config) { debug: false, autoProceed: true, restrictions: { - maxFileSize: page_params.max_file_upload_size * 1024 * 1024, + maxFileSize: page_params.max_file_upload_size_mib * 1024 * 1024, }, locale: { strings: { diff --git a/templates/zerver/app/compose.html b/templates/zerver/app/compose.html index 95517e4ac3..83909a70ae 100644 --- a/templates/zerver/app/compose.html +++ b/templates/zerver/app/compose.html @@ -97,7 +97,7 @@ - {% if max_file_upload_size > 0 %} + {% if max_file_upload_size_mib > 0 %} {% endif %} diff --git a/templates/zerver/app/settings_overlay.html b/templates/zerver/app/settings_overlay.html index e4c3263155..58817c7ce4 100644 --- a/templates/zerver/app/settings_overlay.html +++ b/templates/zerver/app/settings_overlay.html @@ -33,7 +33,7 @@
{{ _('Alert words') }}
- {% if max_file_upload_size > 0 %} + {% if max_file_upload_size_mib > 0 %}
  • {{ _('Uploaded files') }}
    diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py index 6051f349b4..d0ede77e85 100644 --- a/zerver/tests/test_home.py +++ b/zerver/tests/test_home.py @@ -100,8 +100,8 @@ class HomeTest(ZulipTestCase): "last_event_id", "left_side_userlist", "login_page", - "max_avatar_file_size", - "max_file_upload_size", + "max_avatar_file_size_mib", + "max_file_upload_size_mib", "max_icon_file_size", "max_logo_file_size", "max_message_id", diff --git a/zerver/views/home.py b/zerver/views/home.py index e3cb4d0c59..40d26eeb32 100644 --- a/zerver/views/home.py +++ b/zerver/views/home.py @@ -246,26 +246,26 @@ def home_real(request: HttpRequest) -> HttpResponse: # These end up in a global JavaScript Object named 'page_params'. page_params = dict( # Server settings. - development_environment = settings.DEVELOPMENT, - debug_mode = settings.DEBUG, - test_suite = settings.TEST_SUITE, - poll_timeout = settings.POLL_TIMEOUT, - insecure_desktop_app = insecure_desktop_app, - login_page = settings.HOME_NOT_LOGGED_IN, - root_domain_uri = settings.ROOT_DOMAIN_URI, - max_file_upload_size = settings.MAX_FILE_UPLOAD_SIZE, - max_avatar_file_size = settings.MAX_AVATAR_FILE_SIZE, - server_generation = settings.SERVER_GENERATION, - save_stacktraces = settings.SAVE_FRONTEND_STACKTRACES, - warn_no_email = settings.WARN_NO_EMAIL, - server_inline_image_preview = settings.INLINE_IMAGE_PREVIEW, + development_environment = settings.DEVELOPMENT, + debug_mode = settings.DEBUG, + test_suite = settings.TEST_SUITE, + poll_timeout = settings.POLL_TIMEOUT, + insecure_desktop_app = insecure_desktop_app, + login_page = settings.HOME_NOT_LOGGED_IN, + root_domain_uri = settings.ROOT_DOMAIN_URI, + max_file_upload_size_mib = settings.MAX_FILE_UPLOAD_SIZE, + max_avatar_file_size_mib = settings.MAX_AVATAR_FILE_SIZE, + server_generation = settings.SERVER_GENERATION, + save_stacktraces = settings.SAVE_FRONTEND_STACKTRACES, + warn_no_email = settings.WARN_NO_EMAIL, + server_inline_image_preview = settings.INLINE_IMAGE_PREVIEW, server_inline_url_embed_preview = settings.INLINE_URL_EMBED_PREVIEW, - password_min_length = settings.PASSWORD_MIN_LENGTH, - password_min_guesses = settings.PASSWORD_MIN_GUESSES, - jitsi_server_url = settings.JITSI_SERVER_URL, - search_pills_enabled = settings.SEARCH_PILLS_ENABLED, - server_avatar_changes_disabled = settings.AVATAR_CHANGES_DISABLED, - server_name_changes_disabled = settings.NAME_CHANGES_DISABLED, + password_min_length = settings.PASSWORD_MIN_LENGTH, + password_min_guesses = settings.PASSWORD_MIN_GUESSES, + jitsi_server_url = settings.JITSI_SERVER_URL, + search_pills_enabled = settings.SEARCH_PILLS_ENABLED, + server_avatar_changes_disabled = settings.AVATAR_CHANGES_DISABLED, + server_name_changes_disabled = settings.NAME_CHANGES_DISABLED, # Misc. extra data. have_initial_messages = user_has_messages, @@ -358,7 +358,7 @@ def home_real(request: HttpRequest) -> HttpResponse: 'show_webathena': show_webathena, 'embedded': narrow_stream is not None, 'invite_as': PreregistrationUser.INVITE_AS, - 'max_file_upload_size': settings.MAX_FILE_UPLOAD_SIZE, + 'max_file_upload_size_mib': settings.MAX_FILE_UPLOAD_SIZE, },) patch_cache_control(response, no_cache=True, no_store=True, must_revalidate=True) return response