mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-31 12:09:17 +08:00
Add error messages to AssetSyncController [SCI-10020]
This commit is contained in:
parent
bd4471b98b
commit
718f5fbfad
2 changed files with 19 additions and 7 deletions
|
@ -9,7 +9,7 @@ class AssetSyncController < ApplicationController
|
||||||
def show
|
def show
|
||||||
asset = Asset.find_by(id: params[:asset_id])
|
asset = Asset.find_by(id: params[:asset_id])
|
||||||
|
|
||||||
head :forbidden unless asset && can_manage_asset?(asset)
|
render_error(:forbidden) and return unless asset && can_manage_asset?(asset)
|
||||||
|
|
||||||
asset_sync_token = current_user.asset_sync_tokens.find_or_create_by(asset_id: params[:asset_id])
|
asset_sync_token = current_user.asset_sync_tokens.find_or_create_by(asset_id: params[:asset_id])
|
||||||
|
|
||||||
|
@ -26,10 +26,9 @@ class AssetSyncController < ApplicationController
|
||||||
|
|
||||||
def update
|
def update
|
||||||
if @asset_sync_token.conflicts?(request.headers['VersionToken'])
|
if @asset_sync_token.conflicts?(request.headers['VersionToken'])
|
||||||
render(
|
conflict_response = AssetSyncTokenSerializer.new(conflicting_asset_copy_token).as_json
|
||||||
json: AssetSyncTokenSerializer.new(conflicting_asset_copy_token).as_json,
|
error_message = { message: I18n.t('assets.conflict_error', filename: @asset.file.filename) }
|
||||||
status: :conflict
|
render json: conflict_response.merge(error_message), status: :conflict
|
||||||
)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -88,6 +87,16 @@ class AssetSyncController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def render_error(status, filename = nil, message = nil)
|
||||||
|
message ||= if filename.present?
|
||||||
|
I18n.t('assets.default_error_with_filename', filename: filename)
|
||||||
|
else
|
||||||
|
I18n.t('assets.default_error')
|
||||||
|
end
|
||||||
|
|
||||||
|
render json: { message: message }, status: status
|
||||||
|
end
|
||||||
|
|
||||||
def conflicting_asset_copy_token
|
def conflicting_asset_copy_token
|
||||||
Asset.transaction do
|
Asset.transaction do
|
||||||
new_asset = @asset.dup
|
new_asset = @asset.dup
|
||||||
|
@ -111,12 +120,12 @@ class AssetSyncController < ApplicationController
|
||||||
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'])
|
||||||
|
|
||||||
head(:unauthorized) and return unless @asset_sync_token&.token_valid?
|
render_error(:unauthorized) and return unless @asset_sync_token&.token_valid?
|
||||||
|
|
||||||
@asset = @asset_sync_token.asset
|
@asset = @asset_sync_token.asset
|
||||||
@current_user = @asset_sync_token.user
|
@current_user = @asset_sync_token.user
|
||||||
|
|
||||||
head :forbidden unless can_manage_asset?(@asset)
|
render_error(:forbidden, @asset.file.filename) and return unless can_manage_asset?(@asset)
|
||||||
end
|
end
|
||||||
|
|
||||||
def log_step_activity(type_of, step, project = nil, message_items = {})
|
def log_step_activity(type_of, step, project = nil, message_items = {})
|
||||||
|
|
|
@ -3617,6 +3617,9 @@ en:
|
||||||
edit_launching_application_modal:
|
edit_launching_application_modal:
|
||||||
title: "Launching application"
|
title: "Launching application"
|
||||||
description: "%{file_name} will now open in %{application}. Saved changes in %{application} will automatically be synced in SciNote."
|
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."
|
||||||
|
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."
|
||||||
|
|
||||||
atwho:
|
atwho:
|
||||||
no_results:
|
no_results:
|
||||||
|
|
Loading…
Reference in a new issue