From 610ee6bdaa7df3150c6292dd3dd48b39baad62f3 Mon Sep 17 00:00:00 2001 From: artoscinote <85488244+artoscinote@users.noreply.github.com> Date: Wed, 10 Aug 2022 12:05:24 +0200 Subject: [PATCH] Don't adjust step position in bulk deletion [SCI-7079] (#4339) --- app/controllers/protocols_controller.rb | 3 +++ app/models/step.rb | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 20349cc65..e4af462e8 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -277,6 +277,9 @@ class ProtocolsController < ApplicationController step_position: { id: step.id, value_for: 'position_plus_one' }) end + # skip adjusting positions after destroy as this is a bulk delete + step.skip_position_adjust = true + step.destroy! end diff --git a/app/models/step.rb b/app/models/step.rb index f6b5b267d..a12b929fd 100644 --- a/app/models/step.rb +++ b/app/models/step.rb @@ -4,6 +4,8 @@ class Step < ApplicationRecord include TinyMceImages include ViewableModel + attr_accessor :skip_position_adjust # to be used in bulk deletion + enum assets_view_mode: { thumbnail: 0, list: 1, inline: 2 } auto_strip_attributes :name, :description, nullify: false @@ -20,7 +22,7 @@ class Step < ApplicationRecord before_validation :set_completed_on, if: :completed_changed? before_save :set_last_modified_by before_destroy :cascade_before_destroy - after_destroy :adjust_positions_after_destroy + after_destroy :adjust_positions_after_destroy, unless: -> { skip_position_adjust } belongs_to :user, inverse_of: :steps belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User', optional: true