2018-07-16 12:31:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-05 15:01:06 -04:00
|
|
|
module Boards
|
2017-08-28 17:56:49 -04:00
|
|
|
class ListService < Boards::BaseService
|
2020-01-25 16:08:43 -05:00
|
|
|
def execute(create_default_board: true)
|
|
|
|
create_board! if create_default_board && parent.boards.empty?
|
2020-01-17 10:08:37 -05:00
|
|
|
|
2020-02-13 10:08:52 -05:00
|
|
|
find_boards
|
2016-10-05 15:01:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-03-28 14:32:13 -04:00
|
|
|
def boards
|
2020-01-17 10:08:37 -05:00
|
|
|
parent.boards.order_by_name_asc
|
|
|
|
end
|
|
|
|
|
|
|
|
def first_board
|
|
|
|
parent.boards.first_board
|
2018-03-28 14:32:13 -04:00
|
|
|
end
|
|
|
|
|
2016-10-05 15:01:06 -04:00
|
|
|
def create_board!
|
2017-08-28 17:56:49 -04:00
|
|
|
Boards::CreateService.new(parent, current_user).execute
|
2016-10-05 15:01:06 -04:00
|
|
|
end
|
2020-02-13 10:08:52 -05:00
|
|
|
|
|
|
|
def find_boards
|
|
|
|
found =
|
|
|
|
if parent.multiple_issue_boards_available?
|
|
|
|
boards
|
|
|
|
else
|
|
|
|
# When multiple issue boards are not available
|
|
|
|
# a user is only allowed to view the default shown board
|
|
|
|
first_board
|
|
|
|
end
|
|
|
|
|
|
|
|
params[:board_id].present? ? [found.find(params[:board_id])] : found
|
|
|
|
end
|
2016-10-05 15:01:06 -04:00
|
|
|
end
|
|
|
|
end
|