diff options
Diffstat (limited to 'app/controllers/concerns/snippets_actions.rb')
-rw-r--r-- | app/controllers/concerns/snippets_actions.rb | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/app/controllers/concerns/snippets_actions.rb b/app/controllers/concerns/snippets_actions.rb index e78723bdda2..51fc12398d9 100644 --- a/app/controllers/concerns/snippets_actions.rb +++ b/app/controllers/concerns/snippets_actions.rb @@ -3,9 +3,18 @@ module SnippetsActions extend ActiveSupport::Concern include SendsBlob + include RendersNotes + include RendersBlob + include PaginatedCollection + include Gitlab::NoteableMetadata included do + skip_before_action :verify_authenticity_token, + if: -> { action_name == 'show' && js_request? } + before_action :redirect_if_binary, only: [:edit, :update] + + respond_to :html end def edit @@ -43,6 +52,58 @@ module SnippetsActions request.format.js? end + # rubocop:disable Gitlab/ModuleWithInstanceVariables + def show + conditionally_expand_blob(blob) + + 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.json do + render_blob_json(blob) + end + + format.js do + if @snippet.embeddable? + render 'shared/snippets/show' + else + head :not_found + end + end + end + end + + def update + update_params = snippet_params.merge(spammable_params) + + service_response = Snippets::UpdateService.new(@snippet.project, current_user, update_params).execute(@snippet) + @snippet = service_response.payload[:snippet] + + handle_repository_error(:edit) + end + + def destroy + service_response = Snippets::DestroyService.new(current_user, @snippet).execute + + if service_response.success? + redirect_to gitlab_dashboard_snippets_path(@snippet), status: :found + elsif service_response.http_status == 403 + access_denied! + else + redirect_to gitlab_snippet_path(@snippet), + status: :found, + alert: service_response.message + end + end + # rubocop:enable Gitlab/ModuleWithInstanceVariables + private def content_disposition |