Commit 1ce351ea authored by Douwe Maan's avatar Douwe Maan

Move push size check to EE module

parent 168c8aa7
......@@ -38,6 +38,19 @@ module EE
super
end
override :check_change_access!
def check_change_access!
return if changes.blank?
check_size_before_push!
check_if_license_blocks_changes!
super
check_push_size!
end
override :check_active_user!
def check_active_user!
return if geo?
......@@ -54,6 +67,45 @@ module EE
def geo?
actor == :geo
end
def check_size_before_push!
if check_size_limit? && project.above_size_limit?
raise ::Gitlab::GitAccess::UnauthorizedError, ::Gitlab::RepositorySizeError.new(project).push_error
end
end
def check_if_license_blocks_changes!
if ::License.block_changes?
message = ::LicenseHelper.license_message(signed_in: true, is_admin: (user && user.admin?))
raise ::Gitlab::GitAccess::UnauthorizedError, strip_tags(message)
end
end
def check_push_size!
return unless check_size_limit?
# If there are worktrees with a HEAD pointing to a non-existent object,
# calls to `git rev-list --all` will fail in git 2.15+. This should also
# clear stale lock files.
project.repository.clean_stale_repository_files
# rubocop: disable CodeReuse/ActiveRecord
push_size_in_bytes = changes_list.sum do |change|
repository.new_blobs(change[:newrev]).sum(&:size)
end
# rubocop: enable CodeReuse/ActiveRecord
if project.changes_will_exceed_size_limit?(push_size_in_bytes)
raise ::Gitlab::GitAccess::UnauthorizedError, ::Gitlab::RepositorySizeError.new(project).new_changes_error
end
end
def check_size_limit?
strong_memoize(:check_size_limit) do
project.size_limit_enabled? &&
changes_list.any? { |change| !::Gitlab::Git.blank_ref?(change[:newrev]) }
end
end
end
end
end
......@@ -268,20 +268,7 @@ module Gitlab
raise UnauthorizedError, ERROR_MESSAGES[:upload]
end
return if changes.blank? # Allow access this is needed for EE.
if check_size_limit? && project.above_size_limit?
raise UnauthorizedError, Gitlab::RepositorySizeError.new(project).push_error
end
if ::License.block_changes?
message = ::LicenseHelper.license_message(signed_in: true, is_admin: (user && user.admin?))
raise UnauthorizedError, strip_tags(message)
end
check_change_access!
check_push_size!
end
def check_change_access!
......@@ -327,25 +314,6 @@ module Gitlab
raise TimeoutError, logger.full_message
end
def check_push_size!
return unless check_size_limit?
# If there are worktrees with a HEAD pointing to a non-existent object,
# calls to `git rev-list --all` will fail in git 2.15+. This should also
# clear stale lock files.
project.repository.clean_stale_repository_files
# rubocop: disable CodeReuse/ActiveRecord
push_size_in_bytes = changes_list.sum do |change|
repository.new_blobs(change[:newrev]).sum(&:size)
end
# rubocop: enable CodeReuse/ActiveRecord
if project.changes_will_exceed_size_limit?(push_size_in_bytes)
raise UnauthorizedError, Gitlab::RepositorySizeError.new(project).new_changes_error
end
end
def deploy_key
actor if deploy_key?
end
......@@ -400,13 +368,6 @@ module Gitlab
protected
def check_size_limit?
strong_memoize(:check_size_limit) do
project.size_limit_enabled? &&
changes_list.any? { |change| !Gitlab::Git.blank_ref?(change[:newrev]) }
end
end
def changes_list
@changes_list ||= Gitlab::ChangesList.new(changes == ANY ? [] : changes)
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