mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-08 14:15:35 +08:00
Prevent deleting asset on step update
This commit is contained in:
parent
d9fa882d6a
commit
1e14955ade
3 changed files with 11 additions and 9 deletions
|
@ -563,7 +563,12 @@ class StepsController < ApplicationController
|
||||||
for pos, attrs in params[key] do
|
for pos, attrs in params[key] do
|
||||||
if attrs[:_destroy] == '1'
|
if attrs[:_destroy] == '1'
|
||||||
if attrs[:id].present?
|
if attrs[:id].present?
|
||||||
attr_params[pos] = { id: attrs[:id], _destroy: '1' }
|
asset = Asset.find_by_id(attrs[:id])
|
||||||
|
if asset.try(&:locked?)
|
||||||
|
asset.errors.add(:base, 'This file is locked.')
|
||||||
|
else
|
||||||
|
attr_params[pos] = { id: attrs[:id], _destroy: '1' }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
params[key].delete(pos)
|
params[key].delete(pos)
|
||||||
elsif has_destroy_params(params[key][pos])
|
elsif has_destroy_params(params[key][pos])
|
||||||
|
|
|
@ -25,7 +25,6 @@ class Asset < ActiveRecord::Base
|
||||||
do_not_validate_attachment_file_type :file
|
do_not_validate_attachment_file_type :file
|
||||||
|
|
||||||
before_file_post_process :allow_styles_on_images
|
before_file_post_process :allow_styles_on_images
|
||||||
before_destroy :check_if_locked
|
|
||||||
|
|
||||||
# Asset validation
|
# Asset validation
|
||||||
# This could cause some problems if you create empty asset and want to
|
# This could cause some problems if you create empty asset and want to
|
||||||
|
@ -453,8 +452,4 @@ class Asset < ActiveRecord::Base
|
||||||
|
|
||||||
self.file = data
|
self.file = data
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_if_locked
|
|
||||||
return false if locked?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,8 +3,10 @@
|
||||||
<span class="glyphicon glyphicon-file"></span>
|
<span class="glyphicon glyphicon-file"></span>
|
||||||
<%= t("protocols.steps.new.asset_panel_title") %>
|
<%= t("protocols.steps.new.asset_panel_title") %>
|
||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
<%= ff.remove_nested_fields_link do %>
|
<% unless ff.object.file.exists? && ff.object.locked? %>
|
||||||
<span class="glyphicon glyphicon-remove"></span>
|
<%= ff.remove_nested_fields_link do %>
|
||||||
|
<span class="glyphicon glyphicon-remove"></span>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -23,4 +25,4 @@
|
||||||
<%= ff.file_field :file %>
|
<%= ff.file_field :file %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue