summaryrefslogtreecommitdiff
path: root/app/services/boards/lists/list_service.rb
blob: cf15db4314c93b2f959cf8dc55dd3d76afe10ba6 (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
38
39
# frozen_string_literal: true

module Boards
  module Lists
    class ListService < Boards::BaseService
      def execute(board, create_default_lists: true)
        if create_default_lists && !board.lists.backlog.exists?
          board.lists.create(list_type: :backlog)
        end

        lists = board.lists.preload_associated_models
        lists = lists.with_types(available_list_types_for(board))

        return lists.id_in(params[:list_id]) if params[:list_id].present?

        lists
      end

      private

      def available_list_types_for(board)
        licensed_list_types(board) + visible_lists(board)
      end

      def licensed_list_types(board)
        [List.list_types[:label]]
      end

      def visible_lists(board)
        [].tap do |visible|
          visible << ::List.list_types[:backlog] unless board.hide_backlog_list?
          visible << ::List.list_types[:closed] unless board.hide_closed_list?
        end
      end
    end
  end
end

Boards::Lists::ListService.prepend_mod_with('Boards::Lists::ListService')