Commit a9765fb4 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Introduce has_access_to? so that we could reuse it

Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7383#note_18439108
parent 72147812
......@@ -93,10 +93,10 @@ module ProjectsHelper
end
def project_for_deploy_key(deploy_key)
if deploy_key.projects.include?(@project)
if deploy_key.has_access_to?(@project)
@project
else
deploy_key.projects.find { |project| can?(current_user, :read_project, project) }
deploy_key.projects.find(&current_user.method(:has_access_to?))
end
end
......
......@@ -21,7 +21,11 @@ class DeployKey < Key
self.private?
end
def has_access_to?(project)
projects.include?(project)
end
def can_push_to?(project)
can_push? && projects.include?(project)
can_push? && has_access_to?(project)
end
end
......@@ -501,6 +501,10 @@ class User < ActiveRecord::Base
several_namespaces? || admin
end
def has_access_to?(project)
can?(:read_project, project)
end
def can?(action, subject)
Ability.allowed?(self, action, subject)
end
......
......@@ -9,8 +9,7 @@ module Gitlab
def lfs_deploy_token?(for_project)
type == :lfs_deploy_token &&
actor &&
actor.projects.include?(for_project)
actor.try(:has_access_to?, for_project)
end
def success?
......
......@@ -161,7 +161,7 @@ module Gitlab
def can_read_project?
if deploy_key
project.public? || deploy_key.projects.include?(project)
project.public? || deploy_key.has_access_to?(project)
elsif user
user_access.can_read_project?
else
......
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