Commit 49f1fc83 authored by Małgorzata Ksionek's avatar Małgorzata Ksionek

Refactor go class to stop referencing auth::result.actor directly

parent 718b30c2
......@@ -29,6 +29,18 @@ module Gitlab
def deploy_token
actor.is_a?(DeployToken) ? actor : nil
end
def can?(action)
actor&.can?(action)
end
def can_perform_action_on_project?(action, given_project)
Ability.allowed?(actor, action, given_project)
end
def authentication_abilities_include?(ability)
authentication_abilities.include?(ability)
end
end
end
end
......
......@@ -127,23 +127,25 @@ module Gitlab
def project_for_paths(paths, request)
project = Project.where_full_path_in(paths).first
return unless Ability.allowed?(current_user(request, project), :read_project, project)
return unless authentication_result(request, project).can_perform_action_on_project?(:read_project, project)
project
end
def current_user(request, project)
return unless has_basic_credentials?(request)
def authentication_result(request, project)
empty_result = Gitlab::Auth::Result.new(nil, nil, nil, nil)
return empty_result unless has_basic_credentials?(request)
login, password = user_name_and_password(request)
auth_result = Gitlab::Auth.find_for_git_client(login, password, project: project, ip: request.ip)
return unless auth_result.success?
return empty_result unless auth_result.success?
return unless auth_result.actor&.can?(:access_git)
return empty_result unless auth_result.can?(:access_git)
return unless auth_result.authentication_abilities.include?(:read_project)
return empty_result unless auth_result.authentication_abilities_include?(:read_project)
auth_result.actor
auth_result
end
end
end
......
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