Welcome to mirror list, hosted at ThFree Co, Russian Federation.

push_check.rb « checks « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 47aa25aae4c9ff451a8b3b64e0ab7a3181b397fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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::ForbiddenError, GitAccess::ERROR_MESSAGES[:push_code]
          end
        end
      end

      private

      def can_push?
        user_access.can_push_for_ref?(ref) ||
          project.branch_allows_collaboration?(user_access.user, branch_name)
      end
    end
  end
end