Validate `:push_code` before checking protected branches

This commit is contained in:
Bob Van Landuyt 2018-03-08 00:08:52 +01:00
parent d11fbccc8d
commit 12e68d6215
1 changed files with 3 additions and 6 deletions

View File

@ -63,15 +63,12 @@ module Gitlab
request_cache def can_push_to_branch?(ref)
return false unless can_access_git?
return false unless user.can?(:push_code, project) || project.branch_allows_maintainer_push?(user, ref)
if protected?(ProtectedBranch, project, ref)
return true if project.user_can_push_to_empty_repo?(user)
protected_branch_accessible_to?(ref, action: :push)
elsif user.can?(:push_code, project)
true
project.user_can_push_to_empty_repo?(user) || protected_branch_accessible_to?(ref, action: :push)
else
project.branch_allows_maintainer_push?(user, ref)
true
end
end