Error display handling fixed for uploads

This commit is contained in:
Christoph Haas 2020-11-22 23:51:23 +01:00
parent 9e455f25eb
commit 169ad369e4
2 changed files with 28 additions and 26 deletions

View file

@ -52,6 +52,8 @@ class PackagesController < ApplicationController
return return
end end
all_errors = []
params[:file].each do |img| params[:file].each do |img|
# Log.log "Uploaded img=#{img.path}" # Log.log "Uploaded img=#{img.path}"
new_screenshot = @package.screenshots.new(simage: img) new_screenshot = @package.screenshots.new(simage: img)
@ -81,22 +83,22 @@ class PackagesController < ApplicationController
@valid_images.push new_screenshot @valid_images.push new_screenshot
else else
Log.log "Screenshot #{new_screenshot.image_file_name} invalid (#{new_screenshot.errors[:image]})." errors = new_screenshot.errors[:simage]
@invalid_images.push new_screenshot.original_filename Log.log "Screenshot #{img.original_filename} invalid (#{errors})."
#@invalid_images.push img.original_filename
#raise
all_errors << "Your file #{img.original_filename} #{errors.join(' and ')}."
end end
end end
errors = [] if all_errors
@invalid_images.each do |image| flash[:error] = all_errors
# errors << "The image #{image.image_file_name} #{image.errors[:image].join(' and ')}."
errors << "The file #{image} is not valid."
flash[:error] = errors.join(" ")
end end
# Redirect back to upload form if all uploads were invalid # Redirect back to upload form if all uploads were invalid
unless @valid_images.any? unless @valid_images.any?
Log.log "No valid images uploaded. Back to upload form." Log.log "No valid images uploaded. Back to upload form."
redirect_to(upload_path, error: errors) and return redirect_to(upload_path, error: all_errors) and return
end end
# Show a list of invalid uploads by default. Or redirect to the review page # Show a list of invalid uploads by default. Or redirect to the review page
@ -234,21 +236,21 @@ class PackagesController < ApplicationController
end end
# Receive an anonymous report from a user to have a screenshot removed. # Receive an anonymous report from a user to have a screenshot removed.
def report_screenshot # def report_screenshot
@screenshot = Screenshot.find(params[:id]) # @screenshot = Screenshot.find(params[:id])
# if verify_recaptcha # # if verify_recaptcha
@screenshot.delete_reason = params[:delete_reason] # @screenshot.delete_reason = params[:delete_reason]
@screenshot.markedfordelete = true # @screenshot.markedfordelete = true
if @screenshot.valid? # if @screenshot.valid?
@screenshot.save! # @screenshot.save!
flash['notice'] = "Screenshot reported. The moderators will deal with it." # flash['notice'] = "Screenshot reported. The moderators will deal with it."
else # else
errors = @screenshot.errors.to_a.join(' and ') # errors = @screenshot.errors.to_a.join(' and ')
flash['alert'] = "Sorry. #{errors}" # flash['alert'] = "Sorry. #{errors}"
end # end
# end # # end
redirect_back(fallback_location: package_path) # redirect_back(fallback_location: package_path)
end # end
# Show an HTML partial with reviews of this package from the Ubuntu API # Show an HTML partial with reviews of this package from the Ubuntu API
# def reviews # def reviews

View file

@ -8,10 +8,10 @@
- next - next
- when 'notice' - when 'notice'
.callout.warning.alert-callout-subtle.radius data-closable=true .callout.warning.alert-callout-subtle.radius data-closable=true
strong< = msg strong< = safe_join(msg, "<br />".html_safe)
- when 'error' - when 'error'
.callout.alert.alert-callout-subtle.radius data-closable=true .callout.alert.alert-callout-subtle.radius data-closable=true
strong< = msg strong< = safe_join(msg, "<br />".html_safe)
- else - else
.callout.primary.alert-callout-subtle.radius data-closable=true .callout.primary.alert-callout-subtle.radius data-closable=true
strong< = msg strong< = safe_join(msg, "<br />".html_safe)