2018-12-04 11:55:49 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Checks
|
2021-06-15 18:09:57 +00:00
|
|
|
class PushCheck < BaseSingleChecker
|
2018-12-04 11:55:49 +00:00
|
|
|
def validate!
|
|
|
|
logger.log_timed("Checking if you are allowed to push...") do
|
|
|
|
unless can_push?
|
2020-02-26 18:09:24 +00:00
|
|
|
raise GitAccess::ForbiddenError, GitAccess::ERROR_MESSAGES[:push_code]
|
2018-12-04 11:55:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def can_push?
|
2020-12-15 03:10:12 +00:00
|
|
|
user_access.can_push_for_ref?(ref) ||
|
2018-12-20 16:40:56 +00:00
|
|
|
project.branch_allows_collaboration?(user_access.user, branch_name)
|
2018-12-04 11:55:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|