Merge pull request #4192 from aignatov-bio/ai-sci-6928-add-activities-to-bulk-step-deleteting

Add activity to bulk step deletion [SCI-6928]
This commit is contained in:
aignatov-bio 2022-07-05 20:11:44 +02:00 committed by GitHub
commit ef71e59c4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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