From 7ac00c5007a933631c46ec876c7e3a32e9423fe2 Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Fri, 16 Feb 2024 13:06:17 +0100 Subject: [PATCH] Fix making backup copy of conflicting files [SCI-10228] --- app/controllers/asset_sync_controller.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/asset_sync_controller.rb b/app/controllers/asset_sync_controller.rb index 01f3e8da8..855bfba53 100644 --- a/app/controllers/asset_sync_controller.rb +++ b/app/controllers/asset_sync_controller.rb @@ -87,11 +87,15 @@ class AssetSyncController < ApplicationController Asset.transaction do new_asset = @asset.dup new_asset.save - new_asset.file.attach( + + blob = ActiveStorage::Blob.create_and_upload!( io: request.body, - filename: "#{@asset.file.filename.base} (#{t('general.copy')}).#{@asset.file.filename.extension}" + filename: "#{@asset.file.filename.base} (#{t('general.copy')}).#{@asset.file.filename.extension}", + metadata: @asset.blob.metadata ) + new_asset.file.attach(blob) + case @asset.parent when Step StepAsset.create!(step: @asset.step, asset: new_asset) @@ -101,6 +105,8 @@ class AssetSyncController < ApplicationController @asset = new_asset.reload + new_asset.post_process_file + current_user.asset_sync_tokens.create!(asset_id: new_asset.id) end end