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

create_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: 183556a1d6b57a5a6365b970bd199ab34b208f62 (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
module Boards
  module Lists
    class CreateService < Boards::BaseService
      def execute(board)
        List.transaction do
          label    = available_labels_for(board).find(params[:label_id])
          position = next_position(board)
          create_list(board, label, position)
        end
      end

      private

      def available_labels_for(board)
        LabelsFinder.new(current_user, project_id: parent.id).execute
      end

      def next_position(board)
        max_position = board.lists.movable.maximum(:position)
        max_position.nil? ? 0 : max_position.succ
      end

      def create_list(board, label, position)
        board.lists.create(label: label, list_type: :label, position: position)
      end
    end
  end
end