Commit d61acd6d authored by Felipe Artur's avatar Felipe Artur

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

parent 87aef527
......@@ -3,19 +3,24 @@ class Groups::BoardsController < Groups::ApplicationController
include BoardsResponses
before_action :assign_endpoint_vars
before_action :boards, only: :index
def index
@boards = Boards::ListService.new(group, current_user).execute
respond_with_boards
end
def show
@board = group.boards.find(params[:id])
@board = boards.find(params[:id])
respond_with_board
end
private
def boards
@boards ||= Boards::ListService.new(group, current_user).execute
end
def assign_endpoint_vars
@boards_endpoint = group_boards_url(group)
@namespace_path = group.to_param
......
......@@ -5,22 +5,25 @@ class Projects::BoardsController < Projects::ApplicationController
before_action :check_issues_available!
before_action :authorize_read_board!, only: [:index, :show]
before_action :boards, only: :index
before_action :assign_endpoint_vars
def index
@boards = Boards::ListService.new(project, current_user).execute
respond_with_boards
end
def show
@board = project.boards.find(params[:id])
@board = boards.find(params[:id])
respond_with_board
end
private
def boards
@boards ||= Boards::ListService.new(project, current_user).execute
end
def assign_endpoint_vars
@boards_endpoint = project_boards_path(project)
@bulk_issues_path = bulk_update_project_issues_path(project)
......
......@@ -8,7 +8,11 @@ module EE
if parent.multiple_issue_boards_available?
super
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
......
---
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
get :index, group_id: group, format: format
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
......@@ -36,6 +36,12 @@ describe Projects::BoardsController do
end
end
describe 'GET show' do
let(:parent) { project }
it_behaves_like 'multiple issue boards show'
end
describe 'POST create' do
context 'with the multiple issue boards available' do
before do
......@@ -102,7 +108,7 @@ describe Projects::BoardsController do
end
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'
......
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