Add endpoint to update project boards

parent 4214d386
......@@ -2,7 +2,7 @@ class Projects::BoardsController < Projects::ApplicationController
include IssuableCollections
before_action :authorize_read_board!, only: [:index, :show]
before_action :authorize_admin_board!, only: [:create]
before_action :authorize_admin_board!, only: [:create, :update]
def index
@boards = ::Boards::ListService.new(project, current_user).execute
......@@ -40,6 +40,23 @@ class Projects::BoardsController < Projects::ApplicationController
end
end
def update
board = project.boards.find(params[:id])
service = ::Boards::UpdateService.new(project, current_user, board_params)
service.execute(board)
respond_to do |format|
format.json do
if board.valid?
render json: serialize_as_json(board)
else
render json: board.errors, status: :unprocessable_entity
end
end
end
end
private
def authorize_admin_board!
......
......@@ -459,7 +459,7 @@ resources :namespaces, path: '/', constraints: { id: /[a-zA-Z.0-9_\-]+/ }, only:
end
end
resources :boards, only: [:index, :show, :create] do
resources :boards, only: [:index, :show, :create, :update] do
scope module: :boards do
resources :issues, only: [:update]
......
......@@ -181,4 +181,60 @@ describe Projects::BoardsController do
format: :json
end
end
describe 'PATCH update' do
let(:board) { create(:board, project: project, name: 'Backend') }
context 'with valid params' do
it 'returns a successful 200 response' do
update_board board: board, name: 'Frontend'
expect(response).to have_http_status(200)
end
it 'returns the updated board' do
update_board board: board, name: 'Frontend'
expect(response).to match_response_schema('board')
end
end
context 'with invalid params' do
it 'returns an unprocessable entity 422 response' do
update_board board: board, name: nil
expect(response).to have_http_status(422)
end
end
context 'with invalid board id' do
it 'returns a not found 404 response' do
update_board board: 999, name: 'Frontend'
expect(response).to have_http_status(404)
end
end
context 'with unauthorized user' do
before do
allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(true)
allow(Ability).to receive(:allowed?).with(user, :admin_board, project).and_return(false)
end
it 'returns a not found 404 response' do
update_board board: board, name: 'Backend'
expect(response.content_type).to eq 'application/json'
expect(response).to have_http_status(404)
end
end
def update_board(board:, name:)
patch :update, namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: board.to_param,
board: { name: name },
format: :json
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