summaryrefslogtreecommitdiff
path: root/lib/gitlab/checks/push_check.rb
blob: f3a52f0986801534398815dc5be9b0a167789125 (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::UnauthorizedError, 'You are not allowed to push code to this project.'
          end
        end
      end

      private

      def can_push?
        user_access.can_do_action?(:push_code) ||
          user_access.can_push_to_branch?(branch_name)
      end
    end
  end
end