Allow creating protected branch when it doesn't exist
if user has either push or merge permissions + Change log entry for fix to creating a branch matching a wildcard fails
This commit is contained in:
parent
c3c053def2
commit
eb9b964054
3 changed files with 15 additions and 2 deletions
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: Allow creating protected branches when user can merge to such branch
|
||||
merge_request: 8458
|
||||
author:
|
|
@ -35,7 +35,9 @@ module Gitlab
|
|||
return true if project.empty_repo? && project.user_can_push_to_empty_repo?(user)
|
||||
|
||||
access_levels = project.protected_branches.matching(ref).map(&:push_access_levels).flatten
|
||||
access_levels.any? { |access_level| access_level.check_access(user) }
|
||||
has_access = access_levels.any? { |access_level| access_level.check_access(user) }
|
||||
|
||||
has_access || !project.repository.branch_exists?(ref) && can_merge_to_branch?(ref)
|
||||
else
|
||||
user.can?(:push_code, project)
|
||||
end
|
||||
|
|
|
@ -66,7 +66,8 @@ describe Gitlab::UserAccess, lib: true do
|
|||
end
|
||||
|
||||
describe 'push to protected branch' do
|
||||
let(:branch) { create :protected_branch, project: project }
|
||||
let(:branch) { create :protected_branch, project: project, name: "test" }
|
||||
let(:not_existing_branch) { create :protected_branch, :developers_can_merge, project: project }
|
||||
|
||||
it 'returns true if user is a master' do
|
||||
project.team << [user, :master]
|
||||
|
@ -85,6 +86,12 @@ describe Gitlab::UserAccess, lib: true do
|
|||
|
||||
expect(access.can_push_to_branch?(branch.name)).to be_falsey
|
||||
end
|
||||
|
||||
it 'returns true if branch does not exist and user has permission to merge' do
|
||||
project.team << [user, :developer]
|
||||
|
||||
expect(access.can_push_to_branch?(not_existing_branch.name)).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
describe 'push to protected branch if allowed for developers' do
|
||||
|
|
Loading…
Reference in a new issue