FIX: Trigger before upload event after saving and before uploading it, so we are sure that the upload is valid. (#10269)

This commit is contained in:
Roman Rizzi 2020-07-20 17:59:37 -03:00 committed by GitHub
parent 98eb7a3f00
commit 2abfd30d22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,8 +39,6 @@ class UploadCreator
is_image ||= @image_info && FileHelper.is_supported_image?("test.#{@image_info.type}")
is_image = false if @opts[:for_theme]
DiscourseEvent.trigger(:before_upload_creation, @file, is_image)
DistributedMutex.synchronize("upload_#{user_id}_#{@filename}") do
if is_image
extract_image_info!
@ -124,6 +122,8 @@ class UploadCreator
add_metadata!
return @upload unless @upload.save
DiscourseEvent.trigger(:before_upload_creation, @file, is_image)
# store the file and update its url
File.open(@file.path) do |f|
url = Discourse.store.store_upload(f, @upload)