3a0ae96c0e
When the `changes` passed to `GitAccess` are the literal string `_any`, which indicates that this is a pre-authorization check, we now check whether the user can push to any branch in the project in question, instead of running the per-change check with `oldrev` `_any`, `newrev` `nil`, and `ref` `nil`.
22 lines
526 B
Ruby
22 lines
526 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Gitlab
|
|
module Checks
|
|
class PushCheck < BaseChecker
|
|
def validate!
|
|
logger.log_timed("Checking if you are allowed to push...") do
|
|
unless can_push?
|
|
raise GitAccess::UnauthorizedError, GitAccess::ERROR_MESSAGES[:push_code]
|
|
end
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def can_push?
|
|
user_access.can_do_action?(:push_code) ||
|
|
project.branch_allows_collaboration?(user_access.user, branch_name)
|
|
end
|
|
end
|
|
end
|
|
end
|