Commit d6d51d73 authored by Stan Hu's avatar Stan Hu

Merge branch '32427-cannot-reorder-issue-boards' into 'master'

Fix ordering of issue boards

Closes #32427

See merge request gitlab-org/gitlab!17356
parents 6960a5cd 946c2071
...@@ -4,10 +4,10 @@ module Boards ...@@ -4,10 +4,10 @@ module Boards
module Lists module Lists
class UpdateService < Boards::BaseService class UpdateService < Boards::BaseService
def execute(list) def execute(list)
return not_authorized if preferences? && !can_read?(list) update_preferences_result = update_preferences(list) if can_read?(list)
return not_authorized if position? && !can_admin?(list) update_position_result = update_position(list) if can_admin?(list)
if update_preferences(list) || update_position(list) if update_preferences_result || update_position_result
success(list: list) success(list: list)
else else
error(list.errors.messages, 422) error(list.errors.messages, 422)
...@@ -32,10 +32,6 @@ module Boards ...@@ -32,10 +32,6 @@ module Boards
{ collapsed: Gitlab::Utils.to_boolean(params[:collapsed]) } { collapsed: Gitlab::Utils.to_boolean(params[:collapsed]) }
end end
def not_authorized
error("Not authorized", 403)
end
def preferences? def preferences?
params.has_key?(:collapsed) params.has_key?(:collapsed)
end end
......
---
title: Fix ordering of issue board lists not being persisted
merge_request: 17356
author:
type: fixed
...@@ -142,10 +142,10 @@ describe Boards::ListsController do ...@@ -142,10 +142,10 @@ describe Boards::ListsController do
end end
context 'with unauthorized user' do context 'with unauthorized user' do
it 'returns a forbidden 403 response' do it 'returns a 422 unprocessable entity response' do
move user: guest, board: board, list: planning, position: 6 move user: guest, board: board, list: planning, position: 6
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(422)
end end
end end
......
...@@ -162,10 +162,10 @@ describe Boards::ListsController do ...@@ -162,10 +162,10 @@ describe Boards::ListsController do
end end
context 'with unauthorized user' do context 'with unauthorized user' do
it 'returns a forbidden 403 response' do it 'returns a 422 unprocessable entity response' do
move user: guest, board: board, list: planning, position: 6 move user: guest, board: board, list: planning, position: 6
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(422)
end end
end end
......
...@@ -10,9 +10,8 @@ describe Boards::Lists::UpdateService do ...@@ -10,9 +10,8 @@ describe Boards::Lists::UpdateService do
context 'when user can admin list' do context 'when user can admin list' do
it 'calls Lists::MoveService to update list position' do it 'calls Lists::MoveService to update list position' do
board.parent.add_developer(user) board.parent.add_developer(user)
service = described_class.new(board.parent, user, position: 1)
expect(Boards::Lists::MoveService).to receive(:new).with(board.parent, user, { position: 1 }).and_call_original expect(Boards::Lists::MoveService).to receive(:new).with(board.parent, user, params).and_call_original
expect_any_instance_of(Boards::Lists::MoveService).to receive(:execute).with(list) expect_any_instance_of(Boards::Lists::MoveService).to receive(:execute).with(list)
service.execute(list) service.execute(list)
...@@ -21,8 +20,6 @@ describe Boards::Lists::UpdateService do ...@@ -21,8 +20,6 @@ describe Boards::Lists::UpdateService do
context 'when user cannot admin list' do context 'when user cannot admin list' do
it 'does not call Lists::MoveService to update list position' do it 'does not call Lists::MoveService to update list position' do
service = described_class.new(board.parent, user, position: 1)
expect(Boards::Lists::MoveService).not_to receive(:new) expect(Boards::Lists::MoveService).not_to receive(:new)
service.execute(list) service.execute(list)
...@@ -34,7 +31,6 @@ describe Boards::Lists::UpdateService do ...@@ -34,7 +31,6 @@ describe Boards::Lists::UpdateService do
context 'when user can read list' do context 'when user can read list' do
it 'updates list preference for user' do it 'updates list preference for user' do
board.parent.add_guest(user) board.parent.add_guest(user)
service = described_class.new(board.parent, user, collapsed: true)
service.execute(list) service.execute(list)
...@@ -44,8 +40,6 @@ describe Boards::Lists::UpdateService do ...@@ -44,8 +40,6 @@ describe Boards::Lists::UpdateService do
context 'when user cannot read list' do context 'when user cannot read list' do
it 'does not update list preference for user' do it 'does not update list preference for user' do
service = described_class.new(board.parent, user, collapsed: true)
service.execute(list) service.execute(list)
expect(list.preferences_for(user).collapsed).to be_nil expect(list.preferences_for(user).collapsed).to be_nil
...@@ -54,35 +48,61 @@ describe Boards::Lists::UpdateService do ...@@ -54,35 +48,61 @@ describe Boards::Lists::UpdateService do
end end
describe '#execute' do describe '#execute' do
let(:service) { described_class.new(board.parent, user, params) }
context 'when position parameter is present' do context 'when position parameter is present' do
let(:params) { { position: 1 } }
context 'for projects' do context 'for projects' do
it_behaves_like 'moving list' do let(:project) { create(:project, :private) }
let(:project) { create(:project, :private) } let(:board) { create(:board, project: project) }
let(:board) { create(:board, project: project) }
end it_behaves_like 'moving list'
end end
context 'for groups' do context 'for groups' do
it_behaves_like 'moving list' do let(:group) { create(:group, :private) }
let(:group) { create(:group, :private) } let(:board) { create(:board, group: group) }
let(:board) { create(:board, group: group) }
end it_behaves_like 'moving list'
end end
end end
context 'when collapsed parameter is present' do context 'when collapsed parameter is present' do
let(:params) { { collapsed: true } }
context 'for projects' do context 'for projects' do
it_behaves_like 'updating list preferences' do let(:project) { create(:project, :private) }
let(:project) { create(:project, :private) } let(:board) { create(:board, project: project) }
let(:board) { create(:board, project: project) }
end it_behaves_like 'updating list preferences'
end end
context 'for groups' do context 'for groups' do
it_behaves_like 'updating list preferences' do let(:project) { create(:project, :private) }
let(:group) { create(:group, :private) } let(:board) { create(:board, project: project) }
let(:board) { create(:board, group: group) }
end it_behaves_like 'updating list preferences'
end
end
context 'when position and collapsed are both present' do
let(:params) { { collapsed: true, position: 1 } }
context 'for projects' do
let(:project) { create(:project, :private) }
let(:board) { create(:board, project: project) }
it_behaves_like 'moving list'
it_behaves_like 'updating list preferences'
end
context 'for groups' do
let(:group) { create(:group, :private) }
let(:board) { create(:board, group: group) }
it_behaves_like 'moving list'
it_behaves_like 'updating list preferences'
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