Commit 32a265c3 authored by Gosia Ksionek's avatar Gosia Ksionek Committed by Imre Farkas

Refactor git http controller to stop referencing auth::result.actor directly

parent fc0cfaa0
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
# - a `#container` accessor # - a `#container` accessor
# - a `#project` accessor # - a `#project` accessor
# - a `#user` accessor # - a `#user` accessor
# - a `#deploy_token` accessor
# - a `#authentication_result` accessor # - a `#authentication_result` accessor
# - a `#can?(object, action, subject)` method # - a `#can?(object, action, subject)` method
# - a `#ci?` method # - a `#ci?` method
...@@ -83,26 +84,18 @@ module LfsRequest ...@@ -83,26 +84,18 @@ module LfsRequest
end end
def deploy_token_can_download_code? def deploy_token_can_download_code?
deploy_token_present? && deploy_token.present? &&
deploy_token.project == project && deploy_token.project == project &&
deploy_token.active? && deploy_token.active? &&
deploy_token.read_repository? deploy_token.read_repository?
end end
def deploy_token_present?
user && user.is_a?(DeployToken)
end
def deploy_token
user
end
def lfs_upload_access? def lfs_upload_access?
strong_memoize(:lfs_upload_access) do strong_memoize(:lfs_upload_access) do
next false unless has_authentication_ability?(:push_code) next false unless has_authentication_ability?(:push_code)
next false if limit_exceeded? next false if limit_exceeded?
lfs_deploy_token? || can?(user, :push_code, project) lfs_deploy_token? || can?(user, :push_code, project) || can?(deploy_token, :push_code, project)
end end
end end
...@@ -111,7 +104,7 @@ module LfsRequest ...@@ -111,7 +104,7 @@ module LfsRequest
end end
def user_can_download_code? def user_can_download_code?
has_authentication_ability?(:download_code) && can?(user, :download_code, project) && !deploy_token_present? has_authentication_ability?(:download_code) && can?(user, :download_code, project)
end end
def build_can_download_code? def build_can_download_code?
......
...@@ -10,6 +10,10 @@ module Repositories ...@@ -10,6 +10,10 @@ module Repositories
skip_before_action :lfs_check_access!, only: [:deprecated] skip_before_action :lfs_check_access!, only: [:deprecated]
before_action :lfs_check_batch_operation!, only: [:batch] before_action :lfs_check_batch_operation!, only: [:batch]
# added here as a part of the refactor, will be removed
# https://gitlab.com/gitlab-org/gitlab/-/issues/328692
delegate :deploy_token, :user, to: :authentication_result, allow_nil: true
def batch def batch
unless objects.present? unless objects.present?
render_lfs_not_found render_lfs_not_found
...@@ -141,7 +145,7 @@ module Repositories ...@@ -141,7 +145,7 @@ module Repositories
end end
def lfs_auth_header def lfs_auth_header
return unless user.is_a?(User) return unless user
Gitlab::LfsToken.new(user).basic_encoding Gitlab::LfsToken.new(user).basic_encoding
end end
......
...@@ -4,6 +4,10 @@ module Repositories ...@@ -4,6 +4,10 @@ module Repositories
class LfsLocksApiController < Repositories::GitHttpClientController class LfsLocksApiController < Repositories::GitHttpClientController
include LfsRequest include LfsRequest
# added here as a part of the refactor, will be removed
# https://gitlab.com/gitlab-org/gitlab/-/issues/328692
delegate :deploy_token, :user, to: :authentication_result, allow_nil: true
def create def create
@result = Lfs::LockFileService.new(project, user, lfs_params).execute @result = Lfs::LockFileService.new(project, user, lfs_params).execute
......
...@@ -8,6 +8,10 @@ module Repositories ...@@ -8,6 +8,10 @@ module Repositories
skip_before_action :verify_workhorse_api!, only: :download skip_before_action :verify_workhorse_api!, only: :download
# added here as a part of the refactor, will be removed
# https://gitlab.com/gitlab-org/gitlab/-/issues/328692
delegate :deploy_token, :user, to: :authentication_result, allow_nil: true
def download def download
lfs_object = LfsObject.find_by_oid(oid) lfs_object = LfsObject.find_by_oid(oid)
unless lfs_object && lfs_object.file.exists? unless lfs_object && lfs_object.file.exists?
......
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