Commit ad1cda55 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'bw-board-list-by-id' into 'master'

Allow Boards::ListService to find a single board

See merge request gitlab-org/gitlab!24824
parents 49b9944c ae70b705
...@@ -5,13 +5,7 @@ module Boards ...@@ -5,13 +5,7 @@ module Boards
def execute(create_default_board: true) def execute(create_default_board: true)
create_board! if create_default_board && parent.boards.empty? create_board! if create_default_board && parent.boards.empty?
if parent.multiple_issue_boards_available? find_boards
boards
else
# When multiple issue boards are not available
# a user is only allowed to view the default shown board
first_board
end
end end
private private
...@@ -27,5 +21,18 @@ module Boards ...@@ -27,5 +21,18 @@ module Boards
def create_board! def create_board!
Boards::CreateService.new(parent, current_user).execute Boards::CreateService.new(parent, current_user).execute
end end
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
end end
end end
...@@ -50,5 +50,20 @@ RSpec.shared_examples 'multiple boards list service' do ...@@ -50,5 +50,20 @@ RSpec.shared_examples 'multiple boards list service' do
it 'returns boards ordered by name' do it 'returns boards ordered by name' do
expect(service.execute).to eq [board_a, board_B, board_c] expect(service.execute).to eq [board_a, board_B, board_c]
end end
context 'when wanting a specific board' do
it 'returns board specified by id' do
service = described_class.new(parent, double, board_id: board_c.id)
expect(service.execute).to eq [board_c]
end
it 'raises exception when board is not found' do
outside_board = create(:board, resource_parent: create(:project), name: 'outside board')
service = described_class.new(parent, double, board_id: outside_board.id)
expect { service.execute }.to raise_exception(ActiveRecord::RecordNotFound)
end
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment