Commit ae047419 authored by Mark Chao's avatar Mark Chao

Expose paths needed in API

It is helpful to not duplicate these paths in the FE.
parent a354a38f
......@@ -11,6 +11,30 @@ module EE
end
end
def api_approvals_path
if requires_approve?
api_v4_projects_merge_requests_approvals_path(id: project.id, merge_request_iid: merge_request.iid)
end
end
def api_approval_settings_path
if requires_approve?
api_v4_projects_merge_requests_approval_settings_path(id: project.id, merge_request_iid: merge_request.iid)
end
end
def api_approve_path
if requires_approve?
api_v4_projects_merge_requests_approve_path(id: project.id, merge_request_iid: merge_request.iid)
end
end
def api_unapprove_path
if requires_approve?
api_v4_projects_merge_requests_unapprove_path(id: project.id, merge_request_iid: merge_request.iid)
end
end
def target_project
merge_request.target_project.present(current_user: current_user)
end
......
......@@ -128,6 +128,18 @@ module EE
expose :approvals_path do |merge_request|
presenter(merge_request).approvals_path
end
expose :api_approvals_path do |merge_request|
presenter(merge_request).api_approvals_path
end
expose :api_approval_settings_path do |merge_request|
presenter(merge_request).api_approval_settings_path
end
expose :api_approve_path do |merge_request|
presenter(merge_request).api_approve_path
end
expose :api_unapprove_path do |merge_request|
presenter(merge_request).api_unapprove_path
end
end
private
......
......@@ -13,6 +13,38 @@ describe MergeRequestPresenter do
end
end
describe '#api_approvals_path' do
subject { described_class.new(resource, current_user: user).api_approvals_path }
it 'returns path' do
is_expected.to eq("/api/v4/projects/#{resource.project.id}/merge_requests/#{resource.iid}/approvals")
end
end
describe '#api_approval_settings_path' do
subject { described_class.new(resource, current_user: user).api_approval_settings_path }
it 'returns path' do
is_expected.to eq("/api/v4/projects/#{resource.project.id}/merge_requests/#{resource.iid}/approval_settings")
end
end
describe '#api_approve_path' do
subject { described_class.new(resource, current_user: user).api_approve_path }
it 'returns path' do
is_expected.to eq("/api/v4/projects/#{resource.project.id}/merge_requests/#{resource.iid}/approve")
end
end
describe '#api_unapprove_path' do
subject { described_class.new(resource, current_user: user).api_unapprove_path }
it 'returns path' do
is_expected.to eq("/api/v4/projects/#{resource.project.id}/merge_requests/#{resource.iid}/unapprove")
end
end
describe '#approvers_left' do
let!(:private_group) { create(:group_with_members, :private) }
let!(:public_group) { create(:group_with_members) }
......
......@@ -129,6 +129,10 @@
"approvals_before_merge": { "type": ["integer", "null"] },
"approved": { "type": "boolean" },
"approvals_path": { "type": ["string", "null"] },
"api_approvals_path": { "type": ["string", "null"] },
"api_approval_settings_path": { "type": ["string", "null"] },
"api_approve_path": { "type": ["string", "null"] },
"api_unapprove_path": { "type": ["string", "null"] },
"codeclimate": {
"head_path": { "type": "string" },
"base_path": { "type": "string" }
......
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