diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2016-10-25 02:13:24 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2016-10-25 02:13:24 +0800 |
commit | 600da9ee0bb823e4b14fd45d6ff0e5f0b61b9737 (patch) | |
tree | f91eeeee22da72eed5bdf5b87ca27bdc95b136a0 /lib/api/boards.rb | |
parent | 40ff7579e9ba025610dfada9703386b4dc657d6d (diff) | |
parent | cb38290ababe43aca0c635fb87d3a38c4c5debcd (diff) | |
download | gitlab-ce-19737-read-only-auditor.tar.gz |
Merge remote-tracking branch 'upstream/master' into 19737-read-only-auditor19737-read-only-auditor
* upstream/master: (1277 commits)
Grapify the labels API
Fix typo in project settings that prevents users from enabling container registry.
Fix old monitoring links to point to the new location
Added path parameter to Commits API
fixes build with cache:clear issue
Merge branch 'security-fix-leaking-namespace-name' into 'security'
Fix authored vote from notes
Grapify builds API
Add changelog item for groups 404 on relative url
Add relative url support to routing contrainers
Update project member controller to match recent master logic
Add parentheses around return redirect_to method
Trigger change even in select2 test helper to produce production-like behaviour
Refactor js that disable form submit if no members selected
Improve create project member test at project_members_controller_spec
Move changelog item to 8.14
Refactor create member tests from group_members_controller_spec
Refactor groups/projects members controller
Gracefully handle adding of no users to projects and groups
Revert "Change "Group#web_url" to return "/groups/twitter" rather than "/twitter"."
...
Diffstat (limited to 'lib/api/boards.rb')
-rw-r--r-- | lib/api/boards.rb | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/lib/api/boards.rb b/lib/api/boards.rb new file mode 100644 index 00000000000..4ac491edc1b --- /dev/null +++ b/lib/api/boards.rb @@ -0,0 +1,132 @@ +module API + # Boards API + class Boards < Grape::API + before { authenticate! } + + params do + requires :id, type: String, desc: 'The ID of a project' + end + resource :projects do + desc 'Get all project boards' do + detail 'This feature was introduced in 8.13' + success Entities::Board + end + get ':id/boards' do + authorize!(:read_board, user_project) + present user_project.boards, with: Entities::Board + end + + params do + requires :board_id, type: Integer, desc: 'The ID of a board' + end + segment ':id/boards/:board_id' do + helpers do + def project_board + board = user_project.boards.first + + if params[:board_id] == board.id + board + else + not_found!('Board') + end + end + + def board_lists + project_board.lists.destroyable + end + end + + desc 'Get the lists of a project board' do + detail 'Does not include `backlog` and `done` lists. This feature was introduced in 8.13' + success Entities::List + end + get '/lists' do + authorize!(:read_board, user_project) + present board_lists, with: Entities::List + end + + desc 'Get a list of a project board' do + detail 'This feature was introduced in 8.13' + success Entities::List + end + params do + requires :list_id, type: Integer, desc: 'The ID of a list' + end + get '/lists/:list_id' do + authorize!(:read_board, user_project) + present board_lists.find(params[:list_id]), with: Entities::List + end + + desc 'Create a new board list' do + detail 'This feature was introduced in 8.13' + success Entities::List + end + params do + requires :label_id, type: Integer, desc: 'The ID of an existing label' + end + post '/lists' do + unless available_labels.exists?(params[:label_id]) + render_api_error!({ error: 'Label not found!' }, 400) + end + + authorize!(:admin_list, user_project) + + service = ::Boards::Lists::CreateService.new(user_project, current_user, + { label_id: params[:label_id] }) + + list = service.execute(project_board) + + if list.valid? + present list, with: Entities::List + else + render_validation_error!(list) + end + end + + desc 'Moves a board list to a new position' do + detail 'This feature was introduced in 8.13' + success Entities::List + end + params do + requires :list_id, type: Integer, desc: 'The ID of a list' + requires :position, type: Integer, desc: 'The position of the list' + end + put '/lists/:list_id' do + list = project_board.lists.movable.find(params[:list_id]) + + authorize!(:admin_list, user_project) + + service = ::Boards::Lists::MoveService.new(user_project, current_user, + { position: params[:position] }) + + if service.execute(list) + present list, with: Entities::List + else + render_api_error!({ error: "List could not be moved!" }, 400) + end + end + + desc 'Delete a board list' do + detail 'This feature was introduced in 8.13' + success Entities::List + end + params do + requires :list_id, type: Integer, desc: 'The ID of a board list' + end + delete "/lists/:list_id" do + authorize!(:admin_list, user_project) + + list = board_lists.find(params[:list_id]) + + service = ::Boards::Lists::DestroyService.new(user_project, current_user) + + if service.execute(list) + present list, with: Entities::List + else + render_api_error!({ error: 'List could not be deleted!' }, 400) + end + end + end + end + end +end |