mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-17 06:35:14 +08:00
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:
commit
58c6aa3234
3 changed files with 32 additions and 1 deletions
|
@ -24,7 +24,13 @@ class AssetSyncController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
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.file.attach(io: request.body, filename: @asset.file.filename)
|
||||||
@asset.touch
|
@asset.touch
|
||||||
|
@ -34,6 +40,26 @@ class AssetSyncController < ApplicationController
|
||||||
|
|
||||||
# private
|
# 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!
|
def authenticate_asset_sync_token!
|
||||||
@asset_sync_token = AssetSyncToken.find_by(token: request.headers['Authentication'])
|
@asset_sync_token = AssetSyncToken.find_by(token: request.headers['Authentication'])
|
||||||
|
|
||||||
|
|
|
@ -466,6 +466,10 @@ class Asset < ApplicationRecord
|
||||||
(result || step)&.my_module
|
(result || step)&.my_module
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def parent
|
||||||
|
step || result || repository_cell
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def tempdir
|
def tempdir
|
||||||
|
|
|
@ -3690,6 +3690,7 @@ en:
|
||||||
edit: "Edit"
|
edit: "Edit"
|
||||||
delete: "Delete"
|
delete: "Delete"
|
||||||
cancel: "Cancel"
|
cancel: "Cancel"
|
||||||
|
copy: "Copy"
|
||||||
duplicate: "Duplicate"
|
duplicate: "Duplicate"
|
||||||
okay: "Okay"
|
okay: "Okay"
|
||||||
back: "Back"
|
back: "Back"
|
||||||
|
|
Loading…
Reference in a new issue