2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
module SnippetsActions
|
|
|
|
extend ActiveSupport::Concern
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
include RendersNotes
|
|
|
|
include RendersBlob
|
|
|
|
include PaginatedCollection
|
|
|
|
include Gitlab::NoteableMetadata
|
2020-07-28 23:09:34 +05:30
|
|
|
include Snippets::SendBlob
|
|
|
|
include SnippetsSort
|
2023-07-09 08:55:56 +05:30
|
|
|
include ProductAnalyticsTracking
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
included do
|
2020-06-23 00:09:42 +05:30
|
|
|
skip_before_action :verify_authenticity_token,
|
|
|
|
if: -> { action_name == 'show' && js_request? }
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
track_event :show, name: 'i_snippets_show'
|
2021-02-22 17:27:13 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
respond_to :html
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
def edit; end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
# This endpoint is being replaced by Snippets::BlobController#raw
|
|
|
|
# Support for old raw links will be maintainted via this action but
|
|
|
|
# it will only return the first blob found,
|
|
|
|
# see: https://gitlab.com/gitlab-org/gitlab/-/issues/217775
|
2017-08-17 22:00:37 +05:30
|
|
|
def raw
|
2019-02-15 15:39:39 +05:30
|
|
|
workhorse_set_content_type!
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
# Until we don't migrate all snippets to version
|
|
|
|
# snippets we need to support old `SnippetBlob`
|
|
|
|
# blobs
|
|
|
|
if defined?(blob.snippet)
|
|
|
|
send_data(
|
|
|
|
convert_line_endings(blob.data),
|
|
|
|
type: 'text/plain; charset=utf-8',
|
|
|
|
disposition: content_disposition,
|
|
|
|
filename: Snippet.sanitized_file_name(blob.name)
|
|
|
|
)
|
|
|
|
else
|
2020-07-28 23:09:34 +05:30
|
|
|
send_snippet_blob(snippet, blob)
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
def js_request?
|
|
|
|
request.format.js?
|
|
|
|
end
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
# rubocop:disable Gitlab/ModuleWithInstanceVariables
|
|
|
|
def show
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
@note = Note.new(noteable: @snippet, project: @snippet.project)
|
|
|
|
@noteable = @snippet
|
|
|
|
|
|
|
|
@discussions = @snippet.discussions
|
|
|
|
@notes = prepare_notes_for_rendering(@discussions.flat_map(&:notes), @noteable)
|
|
|
|
render 'show'
|
|
|
|
end
|
|
|
|
|
|
|
|
format.js do
|
|
|
|
if @snippet.embeddable?
|
2020-10-24 23:57:45 +05:30
|
|
|
conditionally_expand_blobs(blobs)
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
render 'shared/snippets/show'
|
|
|
|
else
|
|
|
|
head :not_found
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
# rubocop:enable Gitlab/ModuleWithInstanceVariables
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
private
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
def blob
|
2020-10-24 23:57:45 +05:30
|
|
|
@blob ||= blobs.first
|
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
def blobs
|
|
|
|
@blobs ||= if snippet.empty_repo?
|
|
|
|
[snippet.blob]
|
|
|
|
else
|
|
|
|
snippet.blobs
|
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def convert_line_endings(content)
|
|
|
|
params[:line_ending] == 'raw' ? content : content.gsub(/\r\n/, "\n")
|
|
|
|
end
|
|
|
|
end
|