Skip to content

Commit

Permalink
Prevent upload of empty files
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Oct 29, 2023
1 parent 3289e75 commit 4bbcda7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
23 changes: 23 additions & 0 deletions app/assets/javascripts/upload.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/views/submissions/_correction_upload.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
<div class="row mt-2">
<div class="col-12">
<%= 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',
Expand Down

0 comments on commit 4bbcda7

Please sign in to comment.