Merge branch 'bvl-fix-maintainer-push-rejected' into 'master'

Fixes rejected pushes from maintainers

Closes #46337

See merge request gitlab-org/gitlab-ce!18968
This commit is contained in:
Douwe Maan 2018-06-12 08:08:42 +00:00
commit e0de57a836
4 changed files with 36 additions and 4 deletions

View file

@ -2140,10 +2140,14 @@ class Project < ActiveRecord::Base
check_access = -> do
next false if empty_repo?
merge_request = source_of_merge_requests.opened
merge_requests = source_of_merge_requests.opened
.where(allow_collaboration: true)
.find_by(source_branch: branch_name)
merge_request&.can_be_merged_by?(user)
if branch_name
merge_requests.find_by(source_branch: branch_name)&.can_be_merged_by?(user)
else
merge_requests.any? { |merge_request| merge_request.can_be_merged_by?(user) }
end
end
if RequestStore.active?

View file

@ -0,0 +1,6 @@
---
title: Fix bug where maintainer would not be allowed to push to forks with merge requests
that have `Allow maintainer edits` enabled.
merge_request: 18968
author:
type: fixed

View file

@ -3663,6 +3663,11 @@ describe Project do
.to be_truthy
end
it 'allows access when there are merge requests open but no branch name is given' do
expect(project.branch_allows_collaboration?(user, nil))
.to be_truthy
end
it 'does not allow guest users access' do
guest = create(:user)
target_project.add_guest(guest)

View file

@ -1,6 +1,7 @@
require "spec_helper"
describe 'Git HTTP requests' do
include ProjectForksHelper
include TermsHelper
include GitHttpHelpers
include WorkhorseHelpers
@ -305,6 +306,22 @@ describe 'Git HTTP requests' do
expect(response.body).to eq(change_access_error(:push_code))
end
end
context 'when merge requests are open that allow maintainer access' do
let(:canonical_project) { create(:project, :public, :repository) }
let(:project) { fork_project(canonical_project, nil, repository: true) }
before do
canonical_project.add_master(user)
create(:merge_request,
source_project: project,
target_project: canonical_project,
source_branch: 'fixes',
allow_collaboration: true)
end
it_behaves_like 'pushes are allowed'
end
end
end