diff --git a/app/controllers/experiments_controller.rb b/app/controllers/experiments_controller.rb index 37603a9f4..13eb02177 100644 --- a/app/controllers/experiments_controller.rb +++ b/app/controllers/experiments_controller.rb @@ -332,13 +332,19 @@ class ExperimentsController < ApplicationController dst_experiment = @experiment.project.experiments.find(params[:to_experiment_id]) return render_403 unless can_manage_experiment?(dst_experiment) - @experiment.with_lock do + @experiment.transaction do params[:my_module_ids].each do |id| my_module = @experiment.my_modules.find(id) return render_403 unless can_move_my_module?(my_module) modules_to_move[id] = dst_experiment.id end + # Make sure that locks are acquired always in the same order + if dst_experiment.id < @experiment.id + dst_experiment.lock! && @experiment.lock! + else + @experiment.lock! && dst_experiment.lock! + end @experiment.move_modules(modules_to_move, current_user) @experiment.workflowimg.purge diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 944f87143..97ce37c15 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -1,4 +1,3 @@ - class ProtocolsController < ApplicationController include RenamingUtil include ActionView::Helpers::TextHelper @@ -165,7 +164,6 @@ class ProtocolsController < ApplicationController end def show - respond_to do |format| format.json { render json: @protocol, serializer: ProtocolSerializer, user: current_user } format.html @@ -253,9 +251,7 @@ class ProtocolsController < ApplicationController end def delete_steps - @protocol.my_module.lock! - - Protocol.transaction do + @protocol.with_lock do team = @protocol.team previous_size = 0 @protocol.steps.each do |step| @@ -273,7 +269,6 @@ class ProtocolsController < ApplicationController # skip adjusting positions after destroy as this is a bulk delete step.skip_position_adjust = true - step.destroy! end diff --git a/app/models/my_module.rb b/app/models/my_module.rb index 413463669..ed883bf4e 100644 --- a/app/models/my_module.rb +++ b/app/models/my_module.rb @@ -13,9 +13,6 @@ class MyModule < ApplicationRecord include Assignable include Cloneable - ID_PREFIX = 'TA' - include PrefixedIdModel - attr_accessor :transition_error_rollback enum state: Extends::TASKS_STATES diff --git a/app/services/repository_rows/my_module_assign_unassign_service.rb b/app/services/repository_rows/my_module_assign_unassign_service.rb index 905fc81ad..2274bca1d 100644 --- a/app/services/repository_rows/my_module_assign_unassign_service.rb +++ b/app/services/repository_rows/my_module_assign_unassign_service.rb @@ -86,23 +86,19 @@ module RepositoryRows return [] unless params[:rows_to_assign] - my_module.with_lock do - unassigned_rows = @repository.repository_rows - .active - .joins("LEFT OUTER JOIN my_module_repository_rows "\ - "ON repository_rows.id = my_module_repository_rows.repository_row_id "\ - "AND my_module_repository_rows.my_module_id = #{my_module.id.to_i}") - .where(my_module_repository_rows: { id: nil }) - .where(id: @params[:rows_to_assign]) + unassigned_rows = @repository.repository_rows + .active + .joins("LEFT OUTER JOIN my_module_repository_rows " \ + "ON repository_rows.id = my_module_repository_rows.repository_row_id " \ + "AND my_module_repository_rows.my_module_id = #{my_module.id.to_i}") + .where(my_module_repository_rows: { id: nil }) + .where(id: @params[:rows_to_assign]) - return [] unless unassigned_rows.any? + return [] unless unassigned_rows.any? - unassigned_rows.find_each do |repository_row| - MyModuleRepositoryRow.create!(my_module: my_module, - repository_row: repository_row, - assigned_by: @user) - assigned_names << repository_row.name - end + unassigned_rows.find_each do |repository_row| + my_module.my_module_repository_rows.create!(repository_row: repository_row, assigned_by: @user) + assigned_names << repository_row.name end return [] if assigned_names.blank?