From b5a35f583a7d4454a5d189cd3a10851b8aeeab15 Mon Sep 17 00:00:00 2001 From: Anton Ignatov Date: Thu, 18 Jul 2019 15:39:08 +0200 Subject: [PATCH] Fix protocol copy, add metadata to assets --- app/models/concerns/tiny_mce_images.rb | 7 +++++-- app/models/protocol.rb | 4 ++++ app/models/tiny_mce_asset.rb | 5 ++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/models/concerns/tiny_mce_images.rb b/app/models/concerns/tiny_mce_images.rb index b5cc990f2..4d4ba4819 100644 --- a/app/models/concerns/tiny_mce_images.rb +++ b/app/models/concerns/tiny_mce_images.rb @@ -73,7 +73,10 @@ module TinyMceImages tiny_img_clone.transaction do tiny_img_clone.save! - tiny_img_clone.image.attach(io: tiny_img.image.open, filename: tiny_img.image.filename.to_s) + tiny_img_clone.image.attach(io: StringIO.new(tiny_img.image.download), + filename: tiny_img.file_name, + content_type: tiny_img.content_type, + metadata: tiny_img.image.metadata) end target.tiny_mce_assets << tiny_img_clone @@ -96,7 +99,7 @@ module TinyMceImages next if asset && asset.object == self && asset.team_id != asset_team_id - new_image = asset.image + new_image = StringIO.new(asset.image.download) new_image_filename = new_image.file_name else # We need implement size and type checks here diff --git a/app/models/protocol.rb b/app/models/protocol.rb index 942386d98..ebed10671 100644 --- a/app/models/protocol.rb +++ b/app/models/protocol.rb @@ -294,6 +294,10 @@ class Protocol < ApplicationRecord step.assets.each do |asset| asset2 = asset.dup asset2.save! + asset2.file.attach(io: StringIO.new(asset.file.download), + filename: asset.file_name, + content_type: asset.content_type, + metadata: asset.file.metadata) step2.assets << asset2 assets_to_clone << [asset.id, asset2.id] end diff --git a/app/models/tiny_mce_asset.rb b/app/models/tiny_mce_asset.rb index 4178192b7..93da21b3f 100644 --- a/app/models/tiny_mce_asset.rb +++ b/app/models/tiny_mce_asset.rb @@ -170,7 +170,10 @@ class TinyMceAsset < ApplicationRecord tiny_img_clone.transaction do tiny_img_clone.save! - tiny_img_clone.image.attach(io: image.download, filename: image.filename.sanitized) + tiny_img_clone.image.attach(io: StringIO.new(image.download), + filename: file_name, + content_type: content_type, + metadta: image.metadata) end return false unless tiny_img_clone.persisted?