2018-12-04 06:55:49 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Checks
|
2021-06-15 14:09:57 -04:00
|
|
|
class PushCheck < BaseSingleChecker
|
2018-12-04 06:55:49 -05:00
|
|
|
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-14 22:10:12 -05:00
|
|
|
user_access.can_push_for_ref?(ref) ||
|
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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|