Commit 2b7e3055 authored by Nick Thomas's avatar Nick Thomas

Merge branch...

Merge branch '44740-api-to-verify-a-given-user-has-right-to-merge-a-given-mergerequest' into 'master'

API: Expose if the user can merge a given merge request

Closes #44740

See merge request gitlab-org/gitlab-ce!25207
parents 6d1273cf cd6af77f
---
title: 'API: Expose if the current user can merge a MR'
merge_request: 25207
author: Robert Schilling
type: added
...@@ -435,6 +435,9 @@ Parameters: ...@@ -435,6 +435,9 @@ Parameters:
"avatar_url": null, "avatar_url": null,
"web_url" : "https://gitlab.example.com/admin" "web_url" : "https://gitlab.example.com/admin"
}, },
"user" : {
"can_merge" : false
}
"assignee": { "assignee": {
"id": 1, "id": 1,
"name": "Administrator", "name": "Administrator",
......
...@@ -732,6 +732,12 @@ module API ...@@ -732,6 +732,12 @@ module API
def build_available?(options) def build_available?(options)
options[:project]&.feature_available?(:builds, options[:current_user]) options[:project]&.feature_available?(:builds, options[:current_user])
end end
expose :user do
expose :can_merge do |merge_request, options|
merge_request.can_be_merged_by?(options[:current_user])
end
end
end end
class MergeRequestChanges < MergeRequest class MergeRequestChanges < MergeRequest
......
...@@ -372,6 +372,7 @@ describe API::MergeRequests do ...@@ -372,6 +372,7 @@ describe API::MergeRequests do
expect(json_response['force_close_merge_request']).to be_falsy expect(json_response['force_close_merge_request']).to be_falsy
expect(json_response['changes_count']).to eq(merge_request.merge_request_diff.real_size) expect(json_response['changes_count']).to eq(merge_request.merge_request_diff.real_size)
expect(json_response['merge_error']).to eq(merge_request.merge_error) expect(json_response['merge_error']).to eq(merge_request.merge_error)
expect(json_response['user']['can_merge']).to be_truthy
expect(json_response).not_to include('rebase_in_progress') expect(json_response).not_to include('rebase_in_progress')
end end
...@@ -499,6 +500,15 @@ describe API::MergeRequests do ...@@ -499,6 +500,15 @@ describe API::MergeRequests do
expect(json_response['allow_maintainer_to_push']).to be_truthy expect(json_response['allow_maintainer_to_push']).to be_truthy
end end
end end
it 'indicates if a user cannot merge the MR' do
user2 = create(:user)
project.add_reporter(user2)
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user2)
expect(json_response['user']['can_merge']).to be_falsy
end
end end
describe 'GET /projects/:id/merge_requests/:merge_request_iid/participants' do describe 'GET /projects/:id/merge_requests/:merge_request_iid/participants' do
......
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