mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-02 13:12:13 +08:00
Add lock check for editing result
This commit is contained in:
parent
1e14955ade
commit
f727289935
3 changed files with 23 additions and 1 deletions
|
@ -67,7 +67,14 @@ function formAjaxResultAsset($form) {
|
|||
reloadImages($imgs);
|
||||
})
|
||||
.on("ajax:error", function(e, data) {
|
||||
$form.renderFormErrors("result", data.errors, true, e);
|
||||
// This check is here only because of remotipart bug, which returns
|
||||
// HTML instead of JSON, go figure
|
||||
var errors = '';
|
||||
if (data.errors)
|
||||
errors = data.errors;
|
||||
else
|
||||
errors = data.responseJSON.errors;
|
||||
$form.renderFormErrors("result", errors, true, e);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -103,6 +103,7 @@ class ResultAssetsController < ApplicationController
|
|||
def update
|
||||
update_params = result_params
|
||||
previous_size = @result.space_taken
|
||||
previous_asset = @result.asset
|
||||
|
||||
if update_params.key? :asset_attributes
|
||||
asset = Asset.find_by_id(update_params[:asset_attributes][:id])
|
||||
|
@ -136,6 +137,19 @@ class ResultAssetsController < ApplicationController
|
|||
elsif @result.archived_changed?(from: true, to: false)
|
||||
render_403
|
||||
else
|
||||
if previous_asset.locked?
|
||||
@result.errors.add(:asset_attributes,
|
||||
I18n.t('result_assets.edit.locked_file_error'))
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: {
|
||||
status: 'error',
|
||||
errors: @result.errors
|
||||
}, status: :bad_request
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
# Asset (file) and/or name has been changed
|
||||
saved = @result.save
|
||||
|
||||
|
|
|
@ -837,6 +837,7 @@ en:
|
|||
title: "Edit result from task %{module}"
|
||||
uploaded_asset: "Uploaded file"
|
||||
update: "Update file result"
|
||||
locked_file_error: 'This file is being edited by someone else.'
|
||||
create:
|
||||
success_flash: "Successfully added file result to task <strong>%{module}</strong>"
|
||||
update:
|
||||
|
|
Loading…
Reference in a new issue