diff --git a/frontend_tests/node_tests/upload.js b/frontend_tests/node_tests/upload.js index 8b81e82636..ceca0ac29c 100644 --- a/frontend_tests/node_tests/upload.js +++ b/frontend_tests/node_tests/upload.js @@ -101,6 +101,7 @@ run_test('upload_error', () => { var msg_3 = '"foobar.txt" was too large; the maximum file size is 25MB.'; var msg_4 = 'Sorry, the file was too large.'; var msg_5 = 'An unknown error occurred.'; + var msg_6 = 'File and image uploads have been disabled for this organization.'; test('BrowserNotSupported', msg_prefix + msg_1); test('TooManyFiles', msg_prefix + msg_2); @@ -108,6 +109,11 @@ run_test('upload_error', () => { test(413, msg_prefix + msg_4); test(400, 'ちょっと…', {msg: 'ちょっと…'}); test('Do-not-match-any-case', msg_prefix + msg_5); + + // If uploading files has been disabled, then a different error message is + // displayed when a user tries to paste or drag a file onto the UI. + page_params.max_file_upload_size = 0; + test('FileTooLarge', msg_prefix + msg_6, null); }); run_test('upload_finish', () => { diff --git a/static/js/message_edit.js b/static/js/message_edit.js index 35a9e749c1..f299afd45b 100644 --- a/static/js/message_edit.js +++ b/static/js/message_edit.js @@ -274,6 +274,12 @@ function edit_message(row, raw_content) { var editability = get_editability(message, seconds_left_buffer); var is_editable = editability === message_edit.editability_types.TOPIC_ONLY || editability === message_edit.editability_types.FULL; + var max_file_upload_size = page_params.max_file_upload_size; + var file_upload_enabled = false; + + if (max_file_upload_size > 0) { + file_upload_enabled = true; + } var form = $(templates.render( 'message_edit_form', @@ -284,6 +290,7 @@ function edit_message(row, raw_content) { has_been_editable: editability !== editability_types.NO, topic: util.get_message_topic(message), content: raw_content, + file_upload_enabled: file_upload_enabled, minutes_to_edit: Math.floor(page_params.realm_message_content_edit_limit_seconds / 60)})); var edit_obj = {form: form, raw_content: raw_content}; diff --git a/static/js/upload.js b/static/js/upload.js index d5122d3e1f..29c4e4b515 100644 --- a/static/js/upload.js +++ b/static/js/upload.js @@ -101,12 +101,18 @@ exports.options = function (config) { msg = i18n.t("Unable to upload that many files at once."); break; case 'FileTooLarge': - // sanitization not needed as the file name is not potentially parsed as HTML, etc. - var context = { - file_name: file.name, - file_size: page_params.max_file_upload_size, - }; - msg = i18n.t('"__file_name__" was too large; the maximum file size is __file_size__MB.', context); + if (page_params.max_file_upload_size > 0) { + // sanitization not needed as the file name is not potentially parsed as HTML, etc. + var context = { + file_name: file.name, + file_size: page_params.max_file_upload_size, + }; + msg = i18n.t('"__file_name__" was too large; the maximum file size is __file_size__MB.', + context); + } else { + // If uploading files has been disabled. + msg = i18n.t('File and image uploads have been disabled for this organization.'); + } break; case 413: // HTTP status "Request Entity Too Large" msg = i18n.t("Sorry, the file was too large."); diff --git a/static/templates/message_edit_form.handlebars b/static/templates/message_edit_form.handlebars index d5605ae11c..d5aab0574d 100644 --- a/static/templates/message_edit_form.handlebars +++ b/static/templates/message_edit_form.handlebars @@ -41,7 +41,9 @@ {{ _('Drafts') }} diff --git a/templates/zerver/app/settings_overlay.html b/templates/zerver/app/settings_overlay.html index bf226c327b..da96bced6e 100644 --- a/templates/zerver/app/settings_overlay.html +++ b/templates/zerver/app/settings_overlay.html @@ -33,10 +33,12 @@
+ {{#if file_upload_enabled}} + {{/if}} diff --git a/templates/zerver/app/compose.html b/templates/zerver/app/compose.html index 886d86b022..a5286627df 100644 --- a/templates/zerver/app/compose.html +++ b/templates/zerver/app/compose.html @@ -97,8 +97,12 @@ - {% if jitsi_server_url %} - {% endif %} + {% if max_file_upload_size > 0 %} + + {% endif %} + {% if jitsi_server_url %} + + {% endif %}