diff --git a/app/controllers/steps_controller.rb b/app/controllers/steps_controller.rb index aa658bd7d..7c5e4b0c4 100644 --- a/app/controllers/steps_controller.rb +++ b/app/controllers/steps_controller.rb @@ -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]) diff --git a/app/models/asset.rb b/app/models/asset.rb index f4f27ab6d..aa583e160 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -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 diff --git a/app/views/steps/_form_assets.html.erb b/app/views/steps/_form_assets.html.erb index 34ad3656a..9792e1da5 100644 --- a/app/views/steps/_form_assets.html.erb +++ b/app/views/steps/_form_assets.html.erb @@ -3,8 +3,10 @@ <%= t("protocols.steps.new.asset_panel_title") %>
- <%= ff.remove_nested_fields_link do %> - + <% unless ff.object.file.exists? && ff.object.locked? %> + <%= ff.remove_nested_fields_link do %> + + <% end %> <% end %>
@@ -23,4 +25,4 @@ <%= ff.file_field :file %> <% end %> - \ No newline at end of file +