2018-12-04 06:55:49 -05:00
|
|
|
# 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?
|
2020-02-26 13:09:24 -05:00
|
|
|
raise GitAccess::ForbiddenError, GitAccess::ERROR_MESSAGES[:push_code]
|
2018-12-04 06:55:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def can_push?
|
2020-12-09 13:09:48 -05:00
|
|
|
user_access_can_push? ||
|
2018-12-20 11:40:56 -05:00
|
|
|
project.branch_allows_collaboration?(user_access.user, branch_name)
|
2018-12-04 06:55:49 -05:00
|
|
|
end
|
2020-12-09 13:09:48 -05:00
|
|
|
|
|
|
|
def user_access_can_push?
|
|
|
|
if Feature.enabled?(:deploy_keys_on_protected_branches, project)
|
|
|
|
user_access.can_push_to_branch?(ref)
|
|
|
|
else
|
|
|
|
user_access.can_do_action?(:push_code)
|
|
|
|
end
|
|
|
|
end
|
2018-12-04 06:55:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|