From 104825af7980cf3f8f38856db523ca0ad8a4c837 Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Wed, 2 Oct 2024 11:05:45 +0200 Subject: [PATCH] Change how asset sync conflict resolution works with file versioning [SCI-11043] --- app/controllers/asset_sync_controller.rb | 27 ++++++++++++------------ config/locales/en.yml | 2 +- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/app/controllers/asset_sync_controller.rb b/app/controllers/asset_sync_controller.rb index ae8d0e126..968503cd7 100644 --- a/app/controllers/asset_sync_controller.rb +++ b/app/controllers/asset_sync_controller.rb @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 397eb5886..570263530 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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."