diff options
author | Justin DiPierro <dipierroj@gmail.com> | 2016-10-06 12:42:17 -0400 |
---|---|---|
committer | Justin DiPierro <dipierroj@gmail.com> | 2016-10-11 15:36:59 -0400 |
commit | 32186b4ab89e751d42590d2cbfbcf0c6a131bdca (patch) | |
tree | 8f5aa498ce92995b1686bf3ad52c8bc47bf9082f /app/controllers/snippets_controller.rb | |
parent | 0e0984952b458a617cf1f95de8b8fb88ed014d6a (diff) | |
download | gitlab-ce-32186b4ab89e751d42590d2cbfbcf0c6a131bdca.tar.gz |
Added 'Download' button to snippet view
Diffstat (limited to 'app/controllers/snippets_controller.rb')
-rw-r--r-- | app/controllers/snippets_controller.rb | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/app/controllers/snippets_controller.rb b/app/controllers/snippets_controller.rb index d198782138a..dee57e4a388 100644 --- a/app/controllers/snippets_controller.rb +++ b/app/controllers/snippets_controller.rb @@ -1,10 +1,10 @@ class SnippetsController < ApplicationController include ToggleAwardEmoji - before_action :snippet, only: [:show, :edit, :destroy, :update, :raw] + before_action :snippet, only: [:show, :edit, :destroy, :update, :raw, :download] # Allow read snippet - before_action :authorize_read_snippet!, only: [:show, :raw] + before_action :authorize_read_snippet!, only: [:show, :raw, :download] # Allow modify snippet before_action :authorize_update_snippet!, only: [:edit, :update] @@ -12,7 +12,7 @@ class SnippetsController < ApplicationController # Allow destroy snippet before_action :authorize_admin_snippet!, only: [:destroy] - skip_before_action :authenticate_user!, only: [:index, :show, :raw] + skip_before_action :authenticate_user!, only: [:index, :show, :raw, :download] layout 'snippets' respond_to :html @@ -75,6 +75,14 @@ class SnippetsController < ApplicationController ) end + def download + send_data( + @snippet.content, + type: 'text/plain; charset=utf-8', + filename: @snippet.sanitized_file_name + ) + end + protected def snippet |