mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-08 14:15:35 +08:00
Change how asset sync conflict resolution works with file versioning [SCI-11043]
This commit is contained in:
parent
5d7195af2e
commit
104825af79
2 changed files with 14 additions and 15 deletions
|
@ -16,7 +16,8 @@ class AssetSyncController < ApplicationController
|
|||
asset_sync_token = current_user.asset_sync_tokens.find_or_create_by(asset_id: params[:asset_id])
|
||||
|
||||
unless asset_sync_token.token_valid?
|
||||
asset_sync_token = current_user.asset_sync_tokens.create(asset_id: params[:asset_id])
|
||||
asset_sync_token =
|
||||
current_user.asset_sync_tokens.create(asset_id: params[:asset_id])
|
||||
end
|
||||
|
||||
render json: AssetSyncTokenSerializer.new(asset_sync_token).as_json
|
||||
|
@ -27,18 +28,7 @@ class AssetSyncController < ApplicationController
|
|||
end
|
||||
|
||||
def update
|
||||
if @asset_sync_token.conflicts?(request.headers['VersionToken'])
|
||||
ActiveRecord::Base.transaction do
|
||||
conflict_response = AssetSyncTokenSerializer.new(conflicting_asset_copy_token).as_json
|
||||
error_message = { message: I18n.t('assets.conflict_error', filename: @asset.file.filename) }
|
||||
log_activity(:create)
|
||||
render json: conflict_response.merge(error_message), status: :conflict
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
orig_file_size = @asset.file_size
|
||||
asset_conflicts = @asset_sync_token.conflicts?(request.headers['VersionToken'])
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
@asset.update(last_modified_by: current_user)
|
||||
|
@ -49,12 +39,21 @@ class AssetSyncController < ApplicationController
|
|||
@asset.touch
|
||||
end
|
||||
|
||||
@asset.team.release_space(orig_file_size)
|
||||
@asset.post_process_file
|
||||
|
||||
log_activity(:edit)
|
||||
end
|
||||
|
||||
if asset_conflicts
|
||||
ActiveRecord::Base.transaction do
|
||||
conflict_response = AssetSyncTokenSerializer.new(@asset_sync_token).as_json
|
||||
error_message = { message: I18n.t('assets.conflict_error', filename: @asset.file.filename) }
|
||||
render json: conflict_response.merge(error_message), status: :conflict
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
render json: AssetSyncTokenSerializer.new(@asset_sync_token).as_json
|
||||
end
|
||||
|
||||
|
|
|
@ -4049,7 +4049,7 @@ en:
|
|||
edit_launching_application_modal:
|
||||
title: "Launching application"
|
||||
description: "%{file_name} will now open in %{application}. Saved changes in %{application} will automatically be synced in SciNote."
|
||||
conflict_error: "A newer version of the file was already present in the SciNote web app and your file was saved as “%{filename}”. Close this window and re-open file to get the latest changes."
|
||||
conflict_error: "The file got updated in the SciNote web app while you were editing. Your version will be stored as the latest version, and the previous one is kept in version history."
|
||||
default_error: "An error occurred while saving to SciNote. Please save changes to your open document using “Save As…” to avoid losing any working changes."
|
||||
default_error_with_filename: "An error occurred while saving “%{filename}” to SciNote. Please save changes to your open document using “Save As…” to avoid losing any working changes."
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue