From 4bbcda7c979742d55917b9fd87dfe2dfff90780c Mon Sep 17 00:00:00 2001 From: Splines Date: Mon, 30 Oct 2023 00:08:21 +0100 Subject: [PATCH] Prevent upload of empty files --- app/assets/javascripts/upload.coffee | 23 +++++++++++++++++++ .../submissions/_correction_upload.html.erb | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/upload.coffee b/app/assets/javascripts/upload.coffee index c6f40e7bc..8d9c7a082 100644 --- a/app/assets/javascripts/upload.coffee +++ b/app/assets/javascripts/upload.coffee @@ -262,6 +262,20 @@ imageUpload = (fileInput,endpoint='/screenshots/upload', classname="course") -> metaData.innerHTML = data.metadata.filename + ' (' + formatBytes(data.metadata.size) + ')' metaData.style.display = 'inline' + + # Disable upload if empty files were uploaded + # Temporary fix for ":type option required" error in the + # app/controllers/submissions_controller.rb -> show_correction + if data.metadata.size == 0 + $(actualButton).hide() + $('#submit-correction-btn').addClass('disabled') + alert($(actualButton).data('tr-failure')) + else + $(uploadButton).hide() + $(actualButton).show() + $(actualButton).addClass('disabled') + $('#submit-correction-btn').removeClass('disabled') + null hiddenInput true @@ -291,6 +305,15 @@ bulkCorrectionUpload = (fileInput) -> console.log(data) result = (successful: [data]) console.log result + + # Disable upload if uploaded (zip)-file is empty + # Temporary fix for ":type option required" error in the + # app/controllers/submissions_controller.rb -> show_correction + if data.metadata.size == 0 + alert($('#bulk-uploadButton-button-actual').data('tr-failure')) + $('#bulk-uploadButton-button-actual').hide() + return + if result.successful.length > 0 uploaded_files = result.successful.map (file) -> file console.log uploaded_files diff --git a/app/views/submissions/_correction_upload.html.erb b/app/views/submissions/_correction_upload.html.erb index 9fce486b3..885eedd8c 100644 --- a/app/views/submissions/_correction_upload.html.erb +++ b/app/views/submissions/_correction_upload.html.erb @@ -41,7 +41,8 @@
<%= f.submit t('buttons.save'), - class: 'btn btn-sm btn-primary' %> + id: 'submit-correction-btn', + class: 'btn btn-sm btn-primary' %> <%= link_to t('buttons.cancel'), cancel_edit_correction_path(submission), class: 'btn btn-sm btn-secondary',