Commit a39d6fb9 authored by Paul Slaughter's avatar Paul Slaughter

Fix exposed api urls for approval rules

**What happened?**

Previously we simply used the `api_v4.*_path` variable. It turns out
that these variables do not include the `relative_url_root`. We need
to wrap these variables with `expose_uri`, which builds the absolute
URL.
parent 6633afc9
......@@ -13,25 +13,25 @@ module EE
def api_approvals_path
if approval_feature_available?
api_v4_projects_merge_requests_approvals_path(id: project.id, merge_request_iid: merge_request.iid)
expose_url(api_v4_projects_merge_requests_approvals_path(id: project.id, merge_request_iid: merge_request.iid))
end
end
def api_approval_settings_path
if approval_feature_available?
api_v4_projects_merge_requests_approval_settings_path(id: project.id, merge_request_iid: merge_request.iid)
expose_url(api_v4_projects_merge_requests_approval_settings_path(id: project.id, merge_request_iid: merge_request.iid))
end
end
def api_approve_path
if approval_feature_available?
api_v4_projects_merge_requests_approve_path(id: project.id, merge_request_iid: merge_request.iid)
expose_url(api_v4_projects_merge_requests_approve_path(id: project.id, merge_request_iid: merge_request.iid))
end
end
def api_unapprove_path
if approval_feature_available?
api_v4_projects_merge_requests_unapprove_path(id: project.id, merge_request_iid: merge_request.iid)
expose_url(api_v4_projects_merge_requests_unapprove_path(id: project.id, merge_request_iid: merge_request.iid))
end
end
......
......@@ -2,6 +2,6 @@
'can_edit': can?(current_user, :update_approvers, issuable).to_s,
'allow_multi_rule': @target_project.multiple_approval_rules_available?.to_s,
'mr_id': issuable.iid,
'mr_settings_path': issuable.iid && api_v4_projects_merge_requests_approval_settings_path(id: @target_project.id, merge_request_iid: issuable.iid),
'project_settings_path': api_v4_projects_approval_settings_path(id: @target_project.id) } }
'mr_settings_path': issuable.iid && expose_url(api_v4_projects_merge_requests_approval_settings_path(id: @target_project.id, merge_request_iid: issuable.iid)),
'project_settings_path': expose_url(api_v4_projects_approval_settings_path(id: @target_project.id)) } }
= sprite_icon('spinner', size: 24, css_class: 'gl-spinner')
......@@ -2,9 +2,9 @@
= form.label :approver_ids, class: 'label-bold' do
= _("Add approvers")
#js-mr-approvals-settings{ data: { 'project_id': @project.id,
'project_path': api_v4_projects_path(id: @project.id),
'settings_path': api_v4_projects_approval_settings_path(id: @project.id),
'rules_path': api_v4_projects_approval_settings_rules_path(id: @project.id),
'project_path': expose_url(api_v4_projects_path(id: @project.id)),
'settings_path': expose_url(api_v4_projects_approval_settings_path(id: @project.id)),
'rules_path': expose_url(api_v4_projects_approval_settings_rules_path(id: @project.id)),
'allow_multi_rule': @project.multiple_approval_rules_available?.to_s } }
.text-center.prepend-top-default
= sprite_icon('spinner', size: 24, css_class: 'gl-spinner')
---
title: Fix approval rules when used with relative url root
merge_request: 10819
author:
type: fixed
......@@ -5,6 +5,10 @@ describe MergeRequestPresenter do
let!(:project) { create(:project, :repository) }
let!(:user) { project.creator }
before do
stub_config_setting(relative_url_root: '/gitlab')
end
describe '#approvals_path' do
subject { described_class.new(resource, current_user: user).approvals_path }
......@@ -17,7 +21,7 @@ describe MergeRequestPresenter 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")
is_expected.to eq(expose_url("/api/v4/projects/#{resource.project.id}/merge_requests/#{resource.iid}/approvals"))
end
end
......@@ -25,7 +29,7 @@ describe MergeRequestPresenter 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")
is_expected.to eq(expose_url("/api/v4/projects/#{resource.project.id}/merge_requests/#{resource.iid}/approval_settings"))
end
end
......@@ -33,7 +37,7 @@ describe MergeRequestPresenter 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")
is_expected.to eq(expose_url("/api/v4/projects/#{resource.project.id}/merge_requests/#{resource.iid}/approve"))
end
end
......@@ -41,7 +45,7 @@ describe MergeRequestPresenter 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")
is_expected.to eq(expose_url("/api/v4/projects/#{resource.project.id}/merge_requests/#{resource.iid}/unapprove"))
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