From 90c8bb8301b4bc3268a5fa4ea8bddafbc29d6871 Mon Sep 17 00:00:00 2001 From: James Edwards-Jones Date: Tue, 4 Apr 2017 01:39:34 +0100 Subject: [PATCH] Fixed developers_can_push in RepoBranch API entity --- app/models/concerns/protected_ref.rb | 6 ++++++ lib/api/entities.rb | 8 ++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/models/concerns/protected_ref.rb b/app/models/concerns/protected_ref.rb index f6841669ab0..a04dea0bc55 100644 --- a/app/models/concerns/protected_ref.rb +++ b/app/models/concerns/protected_ref.rb @@ -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 diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 0fe7eb864e4..0cc6188938d 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -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