Skip to content
Snippets Groups Projects
Select Git revision
  • move-gl-dropdown
  • improve-table-pagination-spec
  • move-markdown-preview
  • winh-fix-merge-request-spec
  • master default
  • index-namespaces-lower-name
  • winh-single-karma-test
  • 10-3-stable
  • 36782-replace-team-user-role-with-add_role-user-in-specs
  • winh-modal-internal-state
  • tz-ide-file-icons
  • 38869-milestone-select
  • update-autodevops-template
  • jivl-activate-repo-cookie-preferences
  • qa-add-deploy-key
  • docs-move-article-ldap
  • 40780-choose-file
  • 22643-manual-job-page
  • refactor-cluster-show-page-conservative
  • dm-sidekiq-versioning
  • v10.4.0.pre
  • v10.3.0
  • v10.3.0-rc5
  • v10.3.0-rc4
  • v10.3.0-rc3
  • v10.3.0-rc2
  • v10.2.5
  • v10.3.0-rc1
  • v10.0.7
  • v10.1.5
  • v10.2.4
  • v10.2.3
  • v10.2.2
  • v10.2.1
  • v10.3.0.pre
  • v10.2.0
  • v10.2.0-rc4
  • v10.2.0-rc3
  • v10.1.4
  • v10.2.0-rc2
40 results

gitlab.rb

Blame
  • Forked from GitLab.org / GitLab FOSS
    Source project has a limited visibility.
    • Robert Speicher's avatar
      2e13f6c3
      Add `Gitlab.com?` method · 2e13f6c3
      Robert Speicher authored
      To be used as a feature flag for GitLab.com-only features, such as
      welcome emails.
      
      We will be careful to only use this to disable features or functionality
      that do not make sense for any installations that aren't GitLab.com. We
      will not use this to restrict features from other installations or keep
      them "exclusive" to GitLab.com.
      2e13f6c3
      History
      Add `Gitlab.com?` method
      Robert Speicher authored
      To be used as a feature flag for GitLab.com-only features, such as
      welcome emails.
      
      We will be careful to only use this to disable features or functionality
      that do not make sense for any installations that aren't GitLab.com. We
      will not use this to restrict features from other installations or keep
      them "exclusive" to GitLab.com.
    git_http_controller.rb NaN GiB
    # This file should be identical in GitLab Community Edition and Enterprise Edition
    
    class Projects::GitHttpController < Projects::GitHttpClientController
      # GET /foo/bar.git/info/refs?service=git-upload-pack (git pull)
      # GET /foo/bar.git/info/refs?service=git-receive-pack (git push)
      def info_refs
        if upload_pack? && upload_pack_allowed?
          render_ok
        elsif receive_pack? && receive_pack_allowed?
          render_ok
        elsif http_blocked?
          render_http_not_allowed
        else
          render_denied
        end
      end
    
      # POST /foo/bar.git/git-upload-pack (git pull)
      def git_upload_pack
        if upload_pack? && upload_pack_allowed?
          render_ok
        else
          render_denied
        end
      end
    
      # POST /foo/bar.git/git-receive-pack" (git push)
      def git_receive_pack
        if receive_pack? && receive_pack_allowed?
          render_ok
        else
          render_denied
        end
      end
    
      private
    
      def download_request?
        upload_pack?
      end
    
      def upload_pack?
        git_command == 'git-upload-pack'
      end
    
      def receive_pack?
        git_command == 'git-receive-pack'
      end
    
      def git_command
        if action_name == 'info_refs'
          params[:service]
        else
          action_name.dasherize
        end
      end
    
      def render_ok
        render json: Gitlab::Workhorse.git_http_ok(repository, user)
      end
    
      def render_http_not_allowed
        render plain: access_check.message, status: :forbidden
      end
    
      def render_denied
        if user && user.can?(:read_project, project)
          render plain: 'Access denied', status: :forbidden
        else
          # Do not leak information about project existence
          render_not_found
        end
      end
    
      def upload_pack_allowed?
        return false unless Gitlab.config.gitlab_shell.upload_pack
    
        if user
          access_check.allowed?
        else
          ci? || project.public?
        end
      end
    
      def access
        @access ||= Gitlab::GitAccess.new(user, project, 'http')
      end
    
      def access_check
        # Use the magic string '_any' to indicate we do not know what the
        # changes are. This is also what gitlab-shell does.
        @access_check ||= access.check(git_command, '_any')
      end
    
      def http_blocked?
        !access.protocol_allowed?
      end
    
      def receive_pack_allowed?
        return false unless Gitlab.config.gitlab_shell.receive_pack
    
        access_check.allowed?
      end
    end