Commit 4a6686ca authored by Patrick Steinhardt's avatar Patrick Steinhardt

checks: Move per-ref checks into ChangesAccess

Now that we have the ChangesAccess class which handles access checks for
a set of changes, let's also move the SingleChangeAccess checks in
there. Like this, we only have a single class which handles all checks.
parent d1f648de
...@@ -18,6 +18,10 @@ module Gitlab ...@@ -18,6 +18,10 @@ module Gitlab
end end
def validate! def validate!
return if changes.empty?
single_access_checks!
logger.log_timed("Running checks for #{changes.length} changes") do logger.log_timed("Running checks for #{changes.length} changes") do
bulk_access_checks! bulk_access_checks!
end end
...@@ -27,6 +31,24 @@ module Gitlab ...@@ -27,6 +31,24 @@ module Gitlab
protected protected
def single_access_checks!
# Iterate over all changes to find if user allowed all of them to be applied
changes.each.with_index do |change, index|
skip_lfs_integrity_check = index != 0
# If user does not have access to make at least one change, cancel all
# push by allowing the exception to bubble up
Checks::SingleChangeAccess.new(
change,
user_access: user_access,
project: project,
skip_lfs_integrity_check: skip_lfs_integrity_check,
protocol: protocol,
logger: logger
).validate!
end
end
def bulk_access_checks! def bulk_access_checks!
end end
end end
......
...@@ -339,22 +339,6 @@ module Gitlab ...@@ -339,22 +339,6 @@ module Gitlab
end end
def check_access! def check_access!
# Iterate over all changes to find if user allowed all of them to be applied
changes_list.each.with_index do |change, index|
skip_lfs_integrity_check = index != 0
# If user does not have access to make at least one change, cancel all
# push by allowing the exception to bubble up
Checks::SingleChangeAccess.new(
change,
user_access: user_access,
project: project,
skip_lfs_integrity_check: skip_lfs_integrity_check,
protocol: protocol,
logger: logger
).validate!
end
Checks::ChangesAccess.new( Checks::ChangesAccess.new(
changes_list.changes, changes_list.changes,
user_access: user_access, user_access: user_access,
......
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