mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-15 17:44:46 +08:00
Fix move_targets methods to only return active results; prevent moving elements to archived results [SCI-9403]
This commit is contained in:
parent
7319ac5b50
commit
b0511ecec5
4 changed files with 21 additions and 6 deletions
|
@ -71,16 +71,23 @@ class AssetsController < ApplicationController
|
|||
render json: { targets: protocol.steps.order(:position).where.not(id: @assoc.id).map { |i| [i.id, i.name] } }
|
||||
elsif @assoc.is_a?(Result)
|
||||
my_module = @assoc.my_module
|
||||
render json: { targets: my_module.results.where.not(id: @assoc.id).map { |i| [i.id, i.name] } }
|
||||
render json: { targets: my_module.results.active.where.not(id: @assoc.id).map { |i| [i.id, i.name] } }
|
||||
else
|
||||
render json: { targets: [] }
|
||||
end
|
||||
end
|
||||
|
||||
def move
|
||||
case @assoc
|
||||
when Step
|
||||
target = @assoc.protocol.steps.find_by(id: params[:target_id])
|
||||
when Result
|
||||
target = @assoc.my_module.results.active.find_by(id: params[:target_id])
|
||||
return render_404 unless target
|
||||
end
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
if @assoc.is_a?(Step)
|
||||
target = @assoc.protocol.steps.find_by(id: params[:target_id])
|
||||
object_to_update = @asset.step_asset
|
||||
object_to_update.update!(step: target)
|
||||
|
||||
|
@ -114,7 +121,6 @@ class AssetsController < ApplicationController
|
|||
|
||||
render json: {}
|
||||
elsif @assoc.is_a?(Result)
|
||||
target = @assoc.my_module.results.find_by(id: params[:target_id])
|
||||
object_to_update = @asset.result_asset
|
||||
object_to_update.update!(result: target)
|
||||
|
||||
|
|
|
@ -6,7 +6,11 @@ module ResultElements
|
|||
before_action :check_manage_permissions
|
||||
|
||||
def move_targets
|
||||
render json: { targets: @my_module.results.where.not(id: @result.id).map{ |i| [i.id, i.name] } }
|
||||
targets = @my_module.results
|
||||
.active
|
||||
.where.not(id: @result.id)
|
||||
.map { |i| [i.id, i.name] }
|
||||
render json: { targets: targets }
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -58,8 +58,11 @@ module ResultElements
|
|||
end
|
||||
|
||||
def move
|
||||
target = @my_module.results.find_by(id: params[:target_id])
|
||||
target = @my_module.results.active.find_by(id: params[:target_id])
|
||||
return head(:conflict) unless target
|
||||
|
||||
result_table = @table.result_table
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
result_table.update!(result: target)
|
||||
result_table.result_orderable_element.update!(result: target, position: target.result_orderable_elements.size)
|
||||
|
|
|
@ -37,7 +37,9 @@ module ResultElements
|
|||
end
|
||||
|
||||
def move
|
||||
target = @my_module.results.find_by(id: params[:target_id])
|
||||
target = @my_module.results.active.find_by(id: params[:target_id])
|
||||
return head(:conflict) unless target
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
@result_text.update!(result: target)
|
||||
@result_text.result_orderable_element.update!(result: target, position: target.result_orderable_elements.size)
|
||||
|
|
Loading…
Add table
Reference in a new issue