Merge pull request #6564 from artoscinote/ma_SCI_9640

Create a copy of the synced file in case of conflict [SCI-9640]
This commit is contained in:
Martin Artnik 2023-11-03 12:04:56 +01:00 committed by GitHub
commit 58c6aa3234
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 1 deletions

View file

@ -24,7 +24,13 @@ class AssetSyncController < ApplicationController
end
def update
head(:conflict) and return if @asset_sync_token.conflicts?(request.headers['VersionToken'])
if @asset_sync_token.conflicts?(request.headers['VersionToken'])
render(
json: AssetSyncTokenSerializer.new(conflicting_asset_copy_token).as_json,
status: :conflict
)
return
end
@asset.file.attach(io: request.body, filename: @asset.file.filename)
@asset.touch
@ -34,6 +40,26 @@ class AssetSyncController < ApplicationController
# private
def conflicting_asset_copy_token
Asset.transaction do
new_asset = @asset.dup
new_asset.save
new_asset.file.attach(
io: request.body,
filename: "#{@asset.file.filename.base} (#{t('general.copy')}).#{@asset.file.filename.extension}"
)
case @asset.parent
when Step
StepAsset.create!(step: @asset.step, asset: new_asset)
when Result
ResultAsset.create!(result: @asset.result, asset: new_asset)
end
current_user.asset_sync_tokens.create!(asset_id: new_asset.id)
end
end
def authenticate_asset_sync_token!
@asset_sync_token = AssetSyncToken.find_by(token: request.headers['Authentication'])

View file

@ -466,6 +466,10 @@ class Asset < ApplicationRecord
(result || step)&.my_module
end
def parent
step || result || repository_cell
end
private
def tempdir

View file

@ -3690,6 +3690,7 @@ en:
edit: "Edit"
delete: "Delete"
cancel: "Cancel"
copy: "Copy"
duplicate: "Duplicate"
okay: "Okay"
back: "Back"