Commit c8812965 authored by Brett Walker's avatar Brett Walker

Project board names now sorted correctly in CE

and also refactored EE board list service out of
existance, since we now support multiple
project issue boards in CE
parent 0e09920a
...@@ -11,6 +11,7 @@ class Board < ApplicationRecord ...@@ -11,6 +11,7 @@ class Board < ApplicationRecord
validates :group, presence: true, unless: :project validates :group, presence: true, unless: :project
scope :with_associations, -> { preload(:destroyable_lists) } scope :with_associations, -> { preload(:destroyable_lists) }
scope :order_by_name_asc, -> { order(arel_table[:name].lower.asc) }
def project_needed? def project_needed?
!group !group
......
...@@ -4,19 +4,31 @@ module Boards ...@@ -4,19 +4,31 @@ module Boards
class ListService < Boards::BaseService class ListService < Boards::BaseService
def execute def execute
create_board! if parent.boards.empty? create_board! if parent.boards.empty?
if parent.multiple_issue_boards_available?
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
def boards def boards
parent.boards parent.boards.order_by_name_asc
end end
# rubocop: disable CodeReuse/ActiveRecord
def first_board
# We could use just one query but MySQL does not support nested queries using LIMIT
boards.where(id: boards.first).reorder(nil)
end
# rubocop: enable CodeReuse/ActiveRecord
def create_board! def create_board!
Boards::CreateService.new(parent, current_user).execute Boards::CreateService.new(parent, current_user).execute
end end
end end
end end
Boards::ListService.prepend_if_ee('EE::Boards::ListService')
---
title: Project issue board names now sorted correctly in FOSS
merge_request: 22807
author:
type: fixed
# frozen_string_literal: true
module EE
module Boards
module ListService
extend ::Gitlab::Utils::Override
override :execute
# rubocop: disable CodeReuse/ActiveRecord
def execute
if parent.multiple_issue_boards_available?
super
else
# When multiple issue boards is not available
# user is only allowed to view the default shown board
# We could use just one query but MYSQL does not support nested queries using LIMIT.
boards.where(id: super.first).reorder(nil)
end
end
# rubocop: enable CodeReuse/ActiveRecord
private
override :boards
# rubocop: disable CodeReuse/ActiveRecord
def boards
super.order(Arel.sql('LOWER(name) ASC'))
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
...@@ -3,33 +3,20 @@ ...@@ -3,33 +3,20 @@
require 'spec_helper' require 'spec_helper'
describe Boards::ListService do describe Boards::ListService do
shared_examples 'boards list service' do it_behaves_like 'multiple boards list service' do
let(:service) { described_class.new(resource_parent, double) } let(:parent) { create(:project, :empty_repo) }
let!(:boards) { create_list(:board, 3, resource_parent: resource_parent) }
describe '#execute' do before do
it 'returns all issue boards when multiple issue boards is enabled' do
stub_licensed_features(multiple_group_issue_boards: true) stub_licensed_features(multiple_group_issue_boards: true)
expect(service.execute.size).to eq(3)
end
it 'returns boards ordered by name' do
board_names = %w[a-board B-board c-board].shuffle
boards.each_with_index { |board, i| board.update_column(:name, board_names[i]) }
stub_licensed_features(multiple_group_issue_boards: true)
expect(service.execute.pluck(:name)).to eq(%w[a-board B-board c-board])
end
end end
end end
it_behaves_like 'boards list service' do it_behaves_like 'multiple boards list service' do
let(:resource_parent) { create(:project, :empty_repo) } let(:parent) { create(:group) }
end
it_behaves_like 'boards list service' do before do
let(:resource_parent) { create(:group) } stub_licensed_features(multiple_group_issue_boards: true)
end
it 'returns the first issue board when multiple issue boards is disabled' do it 'returns the first issue board when multiple issue boards is disabled' do
stub_licensed_features(multiple_group_issue_boards: false) stub_licensed_features(multiple_group_issue_boards: false)
......
...@@ -10,6 +10,7 @@ describe Boards::ListService do ...@@ -10,6 +10,7 @@ describe Boards::ListService do
subject(:service) { described_class.new(parent, double) } subject(:service) { described_class.new(parent, double) }
it_behaves_like 'boards list service' it_behaves_like 'boards list service'
it_behaves_like 'multiple boards list service'
end end
context 'when board parent is a group' do context 'when board parent is a group' do
......
...@@ -29,3 +29,21 @@ shared_examples 'boards list service' do ...@@ -29,3 +29,21 @@ shared_examples 'boards list service' do
expect(service.execute).to eq [board] expect(service.execute).to eq [board]
end end
end end
shared_examples 'multiple boards list service' do
let(:service) { described_class.new(parent, double) }
let!(:boards) { create_list(:board, 3, resource_parent: parent) }
describe '#execute' do
it 'returns all issue boards' do
expect(service.execute.size).to eq(3)
end
it 'returns boards ordered by name' do
board_names = %w[B-board c-board a-board]
boards.each_with_index { |board, i| board.update_column(:name, board_names[i]) }
expect(service.execute.pluck(:name)).to eq(%w[a-board B-board c-board])
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