Merge pull request #7103 from artoscinote/ma_SCI_10228

Fix making backup copy of conflicting files [SCI-10228]
This commit is contained in:
Martin Artnik 2024-02-16 13:26:40 +01:00 committed by GitHub
commit 41df10a2ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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