From f3fdf25d2fac3f03e0eee7585f99db49d06a3192 Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 4 Jul 2022 21:13:15 +0200 Subject: [PATCH] Add activity to bulk step deletion [SCI-6928] --- app/controllers/protocols_controller.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 0948107a8..b10037d05 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -259,17 +259,29 @@ class ProtocolsController < ApplicationController end def delete_steps + @protocol.my_module.lock! + Protocol.transaction do team = @protocol.team previous_size = 0 - @protocol.steps.each do |step| previous_size += step.space_taken + + if @protocol.in_module? + log_activity(:destroy_step, @protocol.my_module.experiment.project, + my_module: @protocol.my_module.id, + step: step.id, + step_position: { id: step.id, value_for: 'position_plus_one' }) + else + log_activity(:delete_step_in_protocol_repository, nil, step: step.id, + step_position: { id: step.id, value_for: 'position_plus_one' }) + end + step.destroy! end team.release_space(previous_size) - team.save + team.save! render json: { status: 'ok' } rescue ActiveRecord::RecordNotDestroyed render json: { status: 'error' }, status: :unprocessable_entity