Skip to content
Snippets Groups Projects
Commit a9765fb4 authored by Lin Jen-Shin's avatar Lin Jen-Shin
Browse files

Introduce has_access_to? so that we could reuse it

parent 72147812
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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
 
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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?
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment