Don't adjust step position in bulk deletion [SCI-7079] (#4339)

This commit is contained in:
artoscinote 2022-08-10 12:05:24 +02:00 committed by GitHub
parent b91d9e3a28
commit 610ee6bdaa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View file

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

View file

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