debian-mirror-gitlab/app/controllers/concerns/snippets/blobs_actions.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1,004 B
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
module Snippets::BlobsActions
extend ActiveSupport::Concern
include Gitlab::Utils::StrongMemoize
include ExtractsRef
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 repository_container
snippet
end
# rubocop:disable Gitlab/ModuleWithInstanceVariables
def blob
2023-03-04 22:38:38 +05:30
assign_ref_vars
2020-07-28 23:09:34 +05:30
2023-03-04 22:38:38 +05:30
return unless @commit
2020-07-28 23:09:34 +05:30
2023-03-04 22:38:38 +05:30
@repo.blob_at(@commit.id, @path)
2020-07-28 23:09:34 +05:30
end
2023-03-04 22:38:38 +05:30
strong_memoize_attr :blob
2020-07-28 23:09:34 +05:30
# rubocop:enable Gitlab/ModuleWithInstanceVariables
def ensure_blob
render_404 unless blob
end
def ensure_repository
2023-03-04 22:38:38 +05:30
return if snippet.repo_exists?
2020-07-28 23:09:34 +05:30
2023-03-04 22:38:38 +05:30
Gitlab::AppLogger.error(message: "Snippet raw blob attempt with no repo", snippet: snippet.id)
respond_422
2020-07-28 23:09:34 +05:30
end
def snippet_id
params[:snippet_id]
end
end
2022-01-26 12:08:38 +05:30
Snippets::BlobsActions.prepend_mod