Welcome to mirror list, hosted at ThFree Co, Russian Federation.

destroy_service.rb « lists « boards « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ebac0f07fe18f10de929fea105211505f539b94c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# frozen_string_literal: true

module Boards
  module Lists
    class DestroyService < Boards::BaseService
      def execute(list)
        unless list.destroyable?
          return ServiceResponse.error(message: "The list cannot be destroyed. Only label lists can be destroyed.")
        end

        @board = list.board

        list.with_lock do
          decrement_higher_lists(list)
          remove_list(list)
        end

        ServiceResponse.success
      end

      private

      attr_reader :board

      # rubocop: disable CodeReuse/ActiveRecord
      def decrement_higher_lists(list)
        board.lists.movable.where('position > ?', list.position)
                   .update_all('position = position - 1')
      end
      # rubocop: enable CodeReuse/ActiveRecord

      def remove_list(list)
        list.destroy!
      end
    end
  end
end