BigW Consortium Gitlab

Commit a9765fb4 by Lin Jen-Shin

Introduce has_access_to? so that we could reuse it

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