Log activity for content reordering only when order change [SCI-10730]

This commit is contained in:
Andrej 2024-06-17 12:52:48 +02:00
parent df5a414bf5
commit 873a70e425
3 changed files with 32 additions and 15 deletions

View file

@ -5,15 +5,18 @@ class ResultOrderableElementsController < ApplicationController
before_action :check_manage_permissions
def reorder
position_changed = false
ActiveRecord::Base.transaction do
params[:result_orderable_element_positions].each do |id, position|
result_element = @result.result_orderable_elements.find(id)
result_element.insert_at(position)
position_changed ||= result_element.insert_at(position)
end
end
if position_changed
log_activity(:result_content_rearranged, @my_module.experiment.project, my_module: @my_module.id)
@result.touch
end
render json: params[:result_orderable_element_positions], status: :ok
rescue ActiveRecord::RecordInvalid

View file

@ -6,10 +6,16 @@ class StepOrderableElementsController < ApplicationController
def reorder
@step.with_lock do
position_changed = false
params[:step_orderable_element_positions].each do |id, position|
@step.step_orderable_elements.find(id).update_column(:position, position)
step_element = @step.step_orderable_elements.find(id)
if step_element.position != position
position_changed = true
step_element.update_column(:position, position)
end
end
if position_changed
if @protocol.in_module?
log_activity(:task_step_content_rearranged, @my_module.experiment.project, my_module: @my_module.id)
else
@ -17,6 +23,7 @@ class StepOrderableElementsController < ApplicationController
end
@step.touch
end
end
render json: params[:step_orderable_element_positions], status: :ok
end

View file

@ -241,10 +241,16 @@ class StepsController < ApplicationController
def reorder
@protocol.with_lock do
position_changed = false
params[:step_positions].each do |id, position|
@protocol.steps.find(id).update_column(:position, position)
step = @protocol.steps.find(id)
if position != step.position
position_changed = true
step.update_column(:position, position)
end
end
if position_changed
if @protocol.in_module?
log_activity(:task_steps_rearranged, @my_module.experiment.project, my_module: @my_module.id)
else
@ -252,6 +258,7 @@ class StepsController < ApplicationController
end
@protocol.touch
end
end
render json: {
steps_order: @protocol.steps.order(:position).select(:id, :position)