Commit aa537756 authored by Phil Hughes's avatar Phil Hughes

Merge branch...

Merge branch '10601-merge-request-creation-from-fork-fails-due-to-approval-rule-sourcing' into 'master'

Resolve "Merge Request creation from fork fails due to approval rule sourcing"

Closes #10601

See merge request gitlab-org/gitlab-ee!10474
parents 2dedd45a f7a2a6ba
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
= form.label :approver_ids, class: 'col-form-label col-sm-2' do = form.label :approver_ids, class: 'col-form-label col-sm-2' do
Approvers Approvers
.col-sm-10 .col-sm-10
- if Feature.enabled?(:approval_rules, @project) - if Feature.enabled?(:approval_rules, @target_project)
= render 'shared/issuable/approvals_multiple_rule', issuable: issuable = render 'shared/issuable/approvals_multiple_rule', issuable: issuable
- else - else
= render 'shared/issuable/approvals_single_rule', issuable: issuable, presenter: presenter, form: form = 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, '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_id': issuable.iid,
'mr_settings_path': issuable.iid && api_v4_projects_merge_requests_approval_settings_path(id: @project.id, merge_request_iid: 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: @project.id) } } 'project_settings_path': api_v4_projects_approval_settings_path(id: @target_project.id) } }
= sprite_icon('spinner', size: 24, css_class: 'gl-spinner') = 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 @@ ...@@ -3,10 +3,16 @@
require 'rails_helper' require 'rails_helper'
describe 'Merge request > User sets approval rules', :js do describe 'Merge request > User sets approval rules', :js do
include ProjectForksHelper
let(:approver) { create(:user) } let(:approver) { create(:user) }
let(:author) { create(:user) } let(:author) { create(:user) }
let(:project) { create(:project, :public, :repository) } let(:project) { create(:project, :public, :repository) }
def page_rule_names
page.all('.js-approval-rules table .js-name')
end
before do before do
stub_licensed_features(multiple_approval_rules: true) stub_licensed_features(multiple_approval_rules: true)
...@@ -16,12 +22,36 @@ describe 'Merge request > User sets approval rules', :js do ...@@ -16,12 +22,36 @@ describe 'Merge request > User sets approval rules', :js do
end end
context "with project approval rules" do 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 context "with a private group rule" do
let!(:private_group) { create(:group, :private) } let!(:private_group) { create(:group, :private) }
let!(:private_rule) { create(:approval_project_rule, project: project, groups: [private_group], name: 'Private Rule') } 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 before do
private_group.add_developer(approver) private_group.add_developer(approver)
...@@ -32,7 +62,7 @@ describe 'Merge request > User sets approval rules', :js do ...@@ -32,7 +62,7 @@ describe 'Merge request > User sets approval rules', :js do
end end
it "shows approval rules" do 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| rules.each.with_index do |rule, idx|
expect(names[idx]).to have_text(rule.name) expect(names[idx]).to have_text(rule.name)
end end
......
...@@ -12,6 +12,7 @@ describe 'projects/merge_requests/creations/_new_submit.html.haml' do ...@@ -12,6 +12,7 @@ describe 'projects/merge_requests/creations/_new_submit.html.haml' do
assign(:hidden_commit_count, 0) assign(:hidden_commit_count, 0)
assign(:total_commit_count, merge_request.commits.count) assign(:total_commit_count, merge_request.commits.count)
assign(:project, merge_request.target_project) assign(:project, merge_request.target_project)
assign(:target_project, merge_request.target_project)
assign(:mr_presenter, merge_request.present(current_user: merge_request.author)) assign(:mr_presenter, merge_request.present(current_user: merge_request.author))
allow(view).to receive(:can?).and_return(true) allow(view).to receive(:can?).and_return(true)
......
...@@ -23,6 +23,7 @@ describe 'projects/merge_requests/edit.html.haml' do ...@@ -23,6 +23,7 @@ describe 'projects/merge_requests/edit.html.haml' do
before do before do
assign(:project, project) assign(:project, project)
assign(:target_project, project)
assign(:merge_request, closed_merge_request) assign(:merge_request, closed_merge_request)
assign(:mr_presenter, closed_merge_request.present(current_user: user)) 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