Commit 5ae3f375 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'rc/introduce-a-new-ee-lfs_request-module' into 'master'

Introduce a new EE::Concerns::LfsRequest module

See merge request gitlab-org/gitlab-ee!3322
parents 991c509c a303eafb
......@@ -11,6 +11,7 @@ module LfsRequest
extend ActiveSupport::Concern
included do
prepend EE::LfsRequest
before_action :require_lfs_enabled!
before_action :lfs_check_access!
end
......@@ -111,40 +112,4 @@ module LfsRequest
def has_authentication_ability?(capability)
(authentication_abilities || []).include?(capability)
end
module EE
def lfs_forbidden!
raise NotImplementedError unless defined?(super)
if project.above_size_limit? || objects_exceed_repo_limit?
render_size_error
else
super
end
end
def render_size_error
render(
json: {
message: Gitlab::RepositorySizeError.new(project).push_error(@exceeded_limit),
documentation_url: help_url
},
content_type: "application/vnd.git-lfs+json",
status: 406
)
end
def objects_exceed_repo_limit?
return false unless project.size_limit_enabled?
return @limit_exceeded if defined?(@limit_exceeded)
lfs_push_size = objects.sum { |o| o[:size] }
size_with_lfs_push = project.repository_and_lfs_size + lfs_push_size
@exceeded_limit = size_with_lfs_push - project.actual_size_limit
@limit_exceeded = @exceeded_limit > 0
end
end
prepend EE
end
module EE
module LfsRequest
extend ActiveSupport::Concern
def lfs_forbidden!
if project.above_size_limit? || objects_exceed_repo_limit?
render_size_error
else
super
end
end
def render_size_error
render(
json: {
message: ::Gitlab::RepositorySizeError.new(project).push_error(@exceeded_limit),
documentation_url: help_url
},
content_type: "application/vnd.git-lfs+json",
status: 406
)
end
def objects_exceed_repo_limit?
return false unless project.size_limit_enabled?
return @limit_exceeded if defined?(@limit_exceeded)
lfs_push_size = objects.sum { |o| o[:size] }
size_with_lfs_push = project.repository_and_lfs_size + lfs_push_size
@exceeded_limit = size_with_lfs_push - project.actual_size_limit
@limit_exceeded = @exceeded_limit > 0
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