Commit c9557ad7 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Allow maintainers to push to a single branch

parent b2ef8385
...@@ -68,8 +68,12 @@ module Gitlab ...@@ -68,8 +68,12 @@ module Gitlab
return true if project.user_can_push_to_empty_repo?(user) return true if project.user_can_push_to_empty_repo?(user)
protected_branch_accessible_to?(ref, action: :push) protected_branch_accessible_to?(ref, action: :push)
elsif user.can?(:push_code, project)
true
elsif user.can?(:push_single_branch, project)
project.branches_allowing_maintainer_access_to_user(user).include?(ref)
else else
user.can?(:push_code, project) false
end end
end end
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::UserAccess do describe Gitlab::UserAccess do
include ProjectForksHelper
let(:access) { described_class.new(user, project: project) } let(:access) { described_class.new(user, project: project) }
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:user) { create(:user) } let(:user) { create(:user) }
...@@ -118,6 +120,39 @@ describe Gitlab::UserAccess do ...@@ -118,6 +120,39 @@ describe Gitlab::UserAccess do
end end
end end
describe 'allowing pushes to maintainers of forked projects' do
let(:canonical_project) { create(:project, :public, :repository) }
let(:project) { fork_project(canonical_project, create(:user), repository: true) }
before do
create(
:merge_request,
target_project: canonical_project,
source_project: project,
source_branch: 'awesome-feature',
allow_maintainer_to_push: true
)
end
it 'allows users that have push access to the canonical project to push to the MR branch' do
canonical_project.add_developer(user)
expect(access.can_push_to_branch?('awesome-feature')).to be_truthy
end
it 'does not allow the user to push to other branches' do
canonical_project.add_developer(user)
expect(access.can_push_to_branch?('master')).to be_falsey
end
it 'does not allow the user to push if he does not have push access to the canonical project' do
canonical_project.add_guest(user)
expect(access.can_push_to_branch?('awesome-feature')).to be_falsey
end
end
describe 'merge to protected branch if allowed for developers' do describe 'merge to protected branch if allowed for developers' do
before do before do
@branch = create :protected_branch, :developers_can_merge, project: project @branch = create :protected_branch, :developers_can_merge, project: project
......
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