Commit f0486994 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'issue_5128' into 'master'

Allow viewing only one board when multiple issue boards is not enabled

Closes #5128

See merge request gitlab-org/gitlab-ee!5741
parents fff246d3 d61acd6d
...@@ -3,19 +3,24 @@ class Groups::BoardsController < Groups::ApplicationController ...@@ -3,19 +3,24 @@ class Groups::BoardsController < Groups::ApplicationController
include BoardsResponses include BoardsResponses
before_action :assign_endpoint_vars before_action :assign_endpoint_vars
before_action :boards, only: :index
def index def index
@boards = Boards::ListService.new(group, current_user).execute
respond_with_boards respond_with_boards
end end
def show def show
@board = group.boards.find(params[:id]) @board = boards.find(params[:id])
respond_with_board respond_with_board
end end
private
def boards
@boards ||= Boards::ListService.new(group, current_user).execute
end
def assign_endpoint_vars def assign_endpoint_vars
@boards_endpoint = group_boards_url(group) @boards_endpoint = group_boards_url(group)
@namespace_path = group.to_param @namespace_path = group.to_param
......
...@@ -5,22 +5,25 @@ class Projects::BoardsController < Projects::ApplicationController ...@@ -5,22 +5,25 @@ class Projects::BoardsController < Projects::ApplicationController
before_action :check_issues_available! before_action :check_issues_available!
before_action :authorize_read_board!, only: [:index, :show] before_action :authorize_read_board!, only: [:index, :show]
before_action :boards, only: :index
before_action :assign_endpoint_vars before_action :assign_endpoint_vars
def index def index
@boards = Boards::ListService.new(project, current_user).execute
respond_with_boards respond_with_boards
end end
def show def show
@board = project.boards.find(params[:id]) @board = boards.find(params[:id])
respond_with_board respond_with_board
end end
private private
def boards
@boards ||= Boards::ListService.new(project, current_user).execute
end
def assign_endpoint_vars def assign_endpoint_vars
@boards_endpoint = project_boards_path(project) @boards_endpoint = project_boards_path(project)
@bulk_issues_path = bulk_update_project_issues_path(project) @bulk_issues_path = bulk_update_project_issues_path(project)
......
...@@ -8,7 +8,11 @@ module EE ...@@ -8,7 +8,11 @@ module EE
if parent.multiple_issue_boards_available? if parent.multiple_issue_boards_available?
super super
else else
super.limit(1) # 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
end end
......
---
title: Allow viewing only one when multiple issue boards is not enabled
merge_request:
author:
type: other
...@@ -51,4 +51,12 @@ describe Groups::BoardsController do ...@@ -51,4 +51,12 @@ describe Groups::BoardsController do
get :index, group_id: group, format: format get :index, group_id: group, format: format
end end
end end
describe 'GET show' do
context 'for multiple issue boards' do
let(:parent) { group }
it_behaves_like 'multiple issue boards show'
end
end
end end
...@@ -36,6 +36,12 @@ describe Projects::BoardsController do ...@@ -36,6 +36,12 @@ describe Projects::BoardsController do
end end
end end
describe 'GET show' do
let(:parent) { project }
it_behaves_like 'multiple issue boards show'
end
describe 'POST create' do describe 'POST create' do
context 'with the multiple issue boards available' do context 'with the multiple issue boards available' do
before do before do
...@@ -102,7 +108,7 @@ describe Projects::BoardsController do ...@@ -102,7 +108,7 @@ describe Projects::BoardsController do
end end
it 'renders a 404 when multiple issue boards are not available' do it 'renders a 404 when multiple issue boards are not available' do
stub_licensed_features(multiple_issue_boards: false) stub_licensed_features(multiple_project_issue_boards: false)
create_board name: 'Backend' create_board name: 'Backend'
......
require 'spec_helper'
shared_examples 'multiple issue boards show' do
let!(:board1) { create(:board, parent: parent, name: 'b') }
let!(:board2) { create(:board, parent: parent, name: 'a') }
context 'when multiple issue boards is enabled' do
it 'let user view any board from parent' do
[board1, board2].each do |board|
show(board)
expect(response).to have_gitlab_http_status(200)
expect(assigns(:board)).to eq(board)
end
end
end
context 'when multiple issue boards is disabled' do
before do
stub_licensed_features(multiple_project_issue_boards: false, multiple_group_issue_boards: false)
end
it 'let user view the default shown board' do
show(board2)
expect(response).to have_gitlab_http_status(200)
expect(assigns(:board)).to eq(board2)
end
it 'renders 404 when board is not the default' do
show(board1)
expect(response).to have_gitlab_http_status(404)
end
end
def show(board)
params = {}
params[:id] = board.to_param
if board.group_board?
params[:group_id] = parent
else
params.merge!(namespace_id: parent.namespace, project_id: parent)
end
get :show, params
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