Commit f7a2a6ba authored by Paul Slaughter's avatar Paul Slaughter Committed by Phil Hughes

Update `project` to `target_project` in approvals

**Why?**
The merge request should respect the approval rules
of the target project, not the source project.
parent 2dedd45a
......@@ -11,7 +11,7 @@
= form.label :approver_ids, class: 'col-form-label col-sm-2' do
Approvers
.col-sm-10
- if Feature.enabled?(:approval_rules, @project)
- if Feature.enabled?(:approval_rules, @target_project)
= render 'shared/issuable/approvals_multiple_rule', issuable: issuable
- else
= render 'shared/issuable/approvals_single_rule', issuable: issuable, presenter: presenter, form: form
......
#js-mr-approvals-input{ data: { 'project_id': @project.id,
#js-mr-approvals-input{ data: { 'project_id': @target_project.id,
'can_edit': can?(current_user, :update_approvers, issuable).to_s,
'allow_multi_rule': @project.multiple_approval_rules_available?.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: @project.id, merge_request_iid: issuable.iid),
'project_settings_path': api_v4_projects_approval_settings_path(id: @project.id) } }
'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) } }
= sprite_icon('spinner', size: 24, css_class: 'gl-spinner')
---
title: Fix approval rule sourcing from forked MR
merge_request: 10474
author:
type: fixed
......@@ -3,10 +3,16 @@
require 'rails_helper'
describe 'Merge request > User sets approval rules', :js do
include ProjectForksHelper
let(:approver) { create(:user) }
let(:author) { create(:user) }
let(:project) { create(:project, :public, :repository) }
def page_rule_names
page.all('.js-approval-rules table .js-name')
end
before do
stub_licensed_features(multiple_approval_rules: true)
......@@ -16,12 +22,36 @@ describe 'Merge request > User sets approval rules', :js do
end
context "with project approval rules" do
let!(:regular_rule) { create(:approval_project_rule, project: project, users: [approver], name: 'Regular Rule') }
let!(:regular_rules) do
Array.new(3) do |i|
create(:approval_project_rule, project: project, users: [approver], name: "Regular Rule #{i}")
end
end
context "from a fork" do
let(:forked_project) { fork_project(project, nil, repository: true) }
before do
forked_project.add_maintainer(author)
allow(forked_project).to receive(:multiple_approval_rules_available?).and_return(false)
sign_in(author)
visit project_new_merge_request_path(forked_project, merge_request: { target_branch: 'master', target_project_id: project.id, source_branch: 'feature' })
wait_for_requests
end
it "shows approval rules from target project" do
names = page_rule_names
regular_rules.each_with_index do |rule, idx|
expect(names[idx]).to have_text(rule.name)
end
end
end
context "with a private group rule" do
let!(:private_group) { create(:group, :private) }
let!(:private_rule) { create(:approval_project_rule, project: project, groups: [private_group], name: 'Private Rule') }
let!(:rules) { [regular_rule, private_rule] }
let!(:rules) { regular_rules + [private_rule] }
before do
private_group.add_developer(approver)
......@@ -32,7 +62,7 @@ describe 'Merge request > User sets approval rules', :js do
end
it "shows approval rules" do
names = page.all('.js-approval-rules table .js-name')
names = page_rule_names
rules.each.with_index do |rule, idx|
expect(names[idx]).to have_text(rule.name)
end
......
......@@ -12,6 +12,7 @@ describe 'projects/merge_requests/creations/_new_submit.html.haml' do
assign(:hidden_commit_count, 0)
assign(:total_commit_count, merge_request.commits.count)
assign(:project, merge_request.target_project)
assign(:target_project, merge_request.target_project)
assign(:mr_presenter, merge_request.present(current_user: merge_request.author))
allow(view).to receive(:can?).and_return(true)
......
......@@ -23,6 +23,7 @@ describe 'projects/merge_requests/edit.html.haml' do
before do
assign(:project, project)
assign(:target_project, project)
assign(:merge_request, closed_merge_request)
assign(:mr_presenter, closed_merge_request.present(current_user: user))
......
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