Commit 770b2a5c authored by Marin Jankovski's avatar Marin Jankovski

Move protected branch actions into a method.

parent 61b4214e
...@@ -79,18 +79,8 @@ module Gitlab ...@@ -79,18 +79,8 @@ module Gitlab
oldrev, newrev, ref = change.split(' ') oldrev, newrev, ref = change.split(' ')
action = if project.protected_branch?(branch_name(ref)) action = if project.protected_branch?(branch_name(ref))
# we dont allow force push to protected branch protected_branch_action(project, oldrev, newrev, branch_name(ref))
if forced_push?(project, oldrev, newrev) elsif protected_tag?(tag_name(ref))
:force_push_code_to_protected_branches
# and we dont allow remove of protected branch
elsif newrev == Gitlab::Git::BLANK_SHA
:remove_protected_branches
elsif project.developers_can_push_to_protected_branch?(branch_name(ref))
:push_code
else
:push_code_to_protected_branches
end
elsif project.repository.tag_names.include?(tag_name(ref))
# Prevent any changes to existing git tag unless user has permissions # Prevent any changes to existing git tag unless user has permissions
:admin_project :admin_project
else else
...@@ -110,6 +100,24 @@ module Gitlab ...@@ -110,6 +100,24 @@ module Gitlab
private private
def protected_branch_action(project, oldrev, newrev, branch_name)
# we dont allow force push to protected branch
if forced_push?(project, oldrev, newrev)
:force_push_code_to_protected_branches
# and we dont allow remove of protected branch
elsif newrev == Gitlab::Git::BLANK_SHA
:remove_protected_branches
elsif project.developers_can_push_to_protected_branch?(branch_name)
:push_code
else
:push_code_to_protected_branches
end
end
def protected_tag?(tag_name)
project.repository.tag_names.include?(tag_name)
end
def user_allowed?(user) def user_allowed?(user)
Gitlab::UserAccess.allowed?(user) Gitlab::UserAccess.allowed?(user)
end end
......
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