mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 23:16:15 +08:00
Add check for locked files on step delete
This commit is contained in:
parent
5c9e995e56
commit
d9fa882d6a
|
@ -227,29 +227,38 @@ class StepsController < ApplicationController
|
|||
end
|
||||
|
||||
def destroy
|
||||
# Update position on other steps of this module
|
||||
@protocol.steps.where("position > ?", @step.position).each do |step|
|
||||
step.position = step.position - 1
|
||||
step.save
|
||||
if @step.can_destroy?
|
||||
# Update position on other steps of this module
|
||||
@protocol.steps.where('position > ?', @step.position).each do |step|
|
||||
step.position = step.position - 1
|
||||
step.save
|
||||
end
|
||||
|
||||
# Calculate space taken by this step
|
||||
org = @protocol.organization
|
||||
previous_size = @step.space_taken
|
||||
|
||||
# Destroy the step
|
||||
@step.destroy(current_user)
|
||||
|
||||
# Release space taken by the step
|
||||
org.release_space(previous_size)
|
||||
org.save
|
||||
|
||||
# Update protocol timestamp
|
||||
update_protocol_ts(@step)
|
||||
|
||||
flash[:success] = t(
|
||||
'protocols.steps.destroy.success_flash',
|
||||
step: (@step.position + 1).to_s
|
||||
)
|
||||
else
|
||||
flash[:error] = t(
|
||||
'protocols.steps.destroy.error_flash',
|
||||
step: (@step.position + 1).to_s
|
||||
)
|
||||
end
|
||||
|
||||
# Calculate space taken by this step
|
||||
org = @protocol.organization
|
||||
previous_size = @step.space_taken
|
||||
|
||||
# Destroy the step
|
||||
@step.destroy(current_user)
|
||||
|
||||
# Release space taken by the step
|
||||
org.release_space(previous_size)
|
||||
org.save
|
||||
|
||||
# Update protocol timestamp
|
||||
update_protocol_ts(@step)
|
||||
|
||||
flash[:success] = t(
|
||||
"protocols.steps.destroy.success_flash",
|
||||
step: (@step.position + 1).to_s)
|
||||
if @protocol.in_module?
|
||||
redirect_to protocols_my_module_path(@step.my_module)
|
||||
else
|
||||
|
|
|
@ -82,6 +82,10 @@ class Step < ActiveRecord::Base
|
|||
super()
|
||||
end
|
||||
|
||||
def can_destroy?
|
||||
!assets.map(&:locked?).any?
|
||||
end
|
||||
|
||||
def my_module
|
||||
protocol.present? ? protocol.my_module : nil
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<span class="glyphicon glyphicon-edit">
|
||||
</a>
|
||||
<% end %>
|
||||
<% if can_delete_step_in_protocol(@protocol) %>
|
||||
<% if can_delete_step_in_protocol(@protocol) && step.can_destroy? %>
|
||||
<%= link_to(step_path(step), title: t("protocols.steps.options.delete_title"), method: "delete", class: "btn btn-link",
|
||||
data: {action: "delete-step", confirm: t("protocols.steps.destroy.confirm", step: step.name)}) do %>
|
||||
<span class="glyphicon glyphicon-trash">
|
||||
|
|
|
@ -1444,6 +1444,7 @@ en:
|
|||
destroy:
|
||||
confirm: "Are you sure you want to delete step %{step}?"
|
||||
success_flash: "Step %{step} successfully deleted."
|
||||
error_flash: "Step %{step} couldn't be deleted. One or more files are locked."
|
||||
edit:
|
||||
head_title: "Edit protocol"
|
||||
no_keywords: "No keywords"
|
||||
|
|
Loading…
Reference in a new issue