Fixed developers_can_push in RepoBranch API entity

This commit is contained in:
James Edwards-Jones 2017-04-04 01:39:34 +01:00
parent d5acb69e11
commit 90c8bb8301
2 changed files with 8 additions and 6 deletions

View File

@ -14,6 +14,12 @@ module ProtectedRef
end
end
def self.developers_can?(action, ref)
access_levels_for_ref(ref, action: action).any? do |access_level|
access_level.access_level == Gitlab::Access::DEVELOPER
end
end
def self.access_levels_for_ref(ref, action: :push)
self.matching(ref).map(&:"#{action}_access_levels").flatten
end

View File

@ -188,15 +188,11 @@ module API
end
expose :developers_can_push do |repo_branch, options|
project = options[:project]
access_levels = project.protected_branches.access_levels_for_ref(repo_branch.name, :push)
access_levels.any? { |access_level| access_level.access_level == Gitlab::Access::DEVELOPER }
options[:project].protected_branches.developers_can?(:push, repo_branch.name)
end
expose :developers_can_merge do |repo_branch, options|
project = options[:project]
access_levels = project.protected_branches.access_levels_for_ref(repo_branch.name, :merge)
access_levels.any? { |access_level| access_level.access_level == Gitlab::Access::DEVELOPER }
options[:project].protected_branches.developers_can?(:merge, repo_branch.name)
end
end