From c06d29d0aaa3054ff2d131e5a99dbbd56551ee2b Mon Sep 17 00:00:00 2001 From: Vishnu KS Date: Thu, 16 Apr 2020 20:41:06 +0530 Subject: [PATCH] upload: Don't add remaining files if adding a file fails. If a file cannot be added for upload because of restrictions in frontend we call cancelAll immediately in 'info-visible' callback. This would prevent files that are already added to be cancelled but does not cancel files that are yet to be added. So we use break to prevent any more files from being added. --- frontend_tests/node_tests/upload.js | 21 ++++++++++++++++++++- static/js/upload.js | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/frontend_tests/node_tests/upload.js b/frontend_tests/node_tests/upload.js index 81e198ea7a..32c4a2165d 100644 --- a/frontend_tests/node_tests/upload.js +++ b/frontend_tests/node_tests/upload.js @@ -146,7 +146,7 @@ run_test('show_error_message', () => { run_test('upload_files', () => { let uppy_cancel_all_called = false; - const files = [ + let files = [ { name: "budapest.png", type: "image/png", @@ -212,6 +212,25 @@ run_test('upload_files', () => { assert(compose_ui_autosize_textarea_called); assert(uppy_add_file_called); + files = [ + { + name: "budapest.png", + type: "image/png", + }, + { + name: "prague.png", + type: "image/png", + }, + ]; + let add_file_counter = 0; + uppy.addFile = (file) => { + assert.equal(file.name, "budapest.png"); + add_file_counter += 1; + throw Error(); + }; + upload.upload_files(uppy, config, files); + assert.equal(add_file_counter, 1); + global.patch_builtin("setTimeout", (func) => { func(); }); diff --git a/static/js/upload.js b/static/js/upload.js index 4ae627fc0f..70f01c1c28 100644 --- a/static/js/upload.js +++ b/static/js/upload.js @@ -119,6 +119,7 @@ exports.upload_files = function (uppy, config, files) { }); } catch (error) { // Errors are handled by info-visible and upload-error event callbacks. + break; } } };