Prevent deleting asset on step update

This commit is contained in:
Jure Grabnar 2016-10-01 18:47:05 +02:00
parent d9fa882d6a
commit 1e14955ade
3 changed files with 11 additions and 9 deletions

View file

@ -563,7 +563,12 @@ class StepsController < ApplicationController
for pos, attrs in params[key] do
if attrs[:_destroy] == '1'
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
params[key].delete(pos)
elsif has_destroy_params(params[key][pos])

View file

@ -25,7 +25,6 @@ class Asset < ActiveRecord::Base
do_not_validate_attachment_file_type :file
before_file_post_process :allow_styles_on_images
before_destroy :check_if_locked
# Asset validation
# This could cause some problems if you create empty asset and want to
@ -453,8 +452,4 @@ class Asset < ActiveRecord::Base
self.file = data
end
def check_if_locked
return false if locked?
end
end

View file

@ -3,8 +3,10 @@
<span class="glyphicon glyphicon-file"></span>
<%= t("protocols.steps.new.asset_panel_title") %>
<div class="pull-right">
<%= ff.remove_nested_fields_link do %>
<span class="glyphicon glyphicon-remove"></span>
<% unless ff.object.file.exists? && ff.object.locked? %>
<%= ff.remove_nested_fields_link do %>
<span class="glyphicon glyphicon-remove"></span>
<% end %>
<% end %>
</div>
</div>
@ -23,4 +25,4 @@
<%= ff.file_field :file %>
<% end %>
</div>
</div>
</div>