From 2abfd30d223af3af98d283f828d3f0b92b3ac0c8 Mon Sep 17 00:00:00 2001 From: Roman Rizzi Date: Mon, 20 Jul 2020 17:59:37 -0300 Subject: [PATCH] FIX: Trigger before upload event after saving and before uploading it, so we are sure that the upload is valid. (#10269) --- lib/upload_creator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/upload_creator.rb b/lib/upload_creator.rb index 7716af2f31..ea05115b20 100644 --- a/lib/upload_creator.rb +++ b/lib/upload_creator.rb @@ -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)