diff options
author | James Edwards-Jones <jedwardsjones@gitlab.com> | 2017-04-03 15:17:24 +0100 |
---|---|---|
committer | James Edwards-Jones <jedwardsjones@gitlab.com> | 2017-04-03 17:19:53 +0100 |
commit | 65f3d5062f081d8f8ebf727a3408650d90ec9711 (patch) | |
tree | 0246397bd1a234ce9f34b9145321a1c4e40c1cd4 /lib | |
parent | a7c71c7f292c9cdf892f7d33dfb52d7e16af28e6 (diff) | |
download | gitlab-ce-65f3d5062f081d8f8ebf727a3408650d90ec9711.tar.gz |
Extract ProtectedRef Concern
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/entities.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/user_access.rb | 11 |
2 files changed, 5 insertions, 10 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 5954aea8041..e000e3e33d0 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -189,13 +189,13 @@ module API expose :developers_can_push do |repo_branch, options| project = options[:project] - access_levels = project.protected_branches.matching(repo_branch.name).map(&:push_access_levels).flatten + 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 } end expose :developers_can_merge do |repo_branch, options| project = options[:project] - access_levels = project.protected_branches.matching(repo_branch.name).map(&:merge_access_levels).flatten + 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 } end end diff --git a/lib/gitlab/user_access.rb b/lib/gitlab/user_access.rb index 921159d91ef..5a5a4ebd08b 100644 --- a/lib/gitlab/user_access.rb +++ b/lib/gitlab/user_access.rb @@ -35,10 +35,7 @@ module Gitlab return false unless can_access_git? if project.protected_tag?(ref) - access_levels = project.protected_tags.matching(ref).map(&:push_access_levels).flatten - has_access = access_levels.any? { |access_level| access_level.check_access(user) } - - has_access + project.protected_tags.matching_refs_accesible_to(ref, user) else user.can?(:push_code, project) end @@ -50,8 +47,7 @@ module Gitlab if project.protected_branch?(ref) 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 - has_access = access_levels.any? { |access_level| access_level.check_access(user) } + has_access = project.protected_branches.matching_refs_accesible_to(ref, user, action: :push) has_access || !project.repository.branch_exists?(ref) && can_merge_to_branch?(ref) else @@ -63,8 +59,7 @@ module Gitlab return false unless can_access_git? if project.protected_branch?(ref) - access_levels = project.protected_branches.matching(ref).map(&:merge_access_levels).flatten - access_levels.any? { |access_level| access_level.check_access(user) } + project.protected_branches.matching_refs_accesible_to(ref, user, action: :merge) else user.can?(:push_code, project) end |