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

blobs_actions.rb « snippets « concerns « controllers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 955debfc209e32008cbafa7d9441c71915f20a6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true

module Snippets::BlobsActions
  extend ActiveSupport::Concern

  include Gitlab::Utils::StrongMemoize
  include Snippets::SendBlob

  included do
    before_action :authorize_read_snippet!, only: [:raw]
    before_action :ensure_repository
    before_action :ensure_blob
  end

  def raw
    send_snippet_blob(snippet, blob)
  end

  private

  def blob
    ref_extractor = ExtractsRef::RefExtractor.new(snippet, params.permit(:id, :ref, :path, :ref_type))
    ref_extractor.extract!
    return unless ref_extractor.commit

    snippet.repository.blob_at(ref_extractor.commit.id, ref_extractor.path)
  end
  strong_memoize_attr :blob

  def ensure_blob
    render_404 unless blob
  end

  def ensure_repository
    return if snippet.repo_exists?

    Gitlab::AppLogger.error(message: "Snippet raw blob attempt with no repo", snippet: snippet.id)

    respond_422
  end

  def snippet_id
    params[:snippet_id]
  end
end

Snippets::BlobsActions.prepend_mod