summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin DiPierro <dipierroj@gmail.com>2016-10-06 12:42:17 -0400
committerJustin DiPierro <dipierroj@gmail.com>2016-10-11 15:36:59 -0400
commit32186b4ab89e751d42590d2cbfbcf0c6a131bdca (patch)
tree8f5aa498ce92995b1686bf3ad52c8bc47bf9082f
parent0e0984952b458a617cf1f95de8b8fb88ed014d6a (diff)
downloadgitlab-ce-32186b4ab89e751d42590d2cbfbcf0c6a131bdca.tar.gz
Added 'Download' button to snippet view
-rw-r--r--CHANGELOG1
-rw-r--r--app/controllers/snippets_controller.rb14
-rw-r--r--app/views/snippets/show.html.haml1
-rw-r--r--config/routes/snippets.rb1
4 files changed, 14 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG
index e2480b66ae4..ad34e7476ce 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -38,6 +38,7 @@ v 8.13.0 (unreleased)
- Fix todos page mobile viewport layout (ClemMakesApps)
- Fix inconsistent highlighting of already selected activity nav-links (ClemMakesApps)
- Remove redundant mixins (ClemMakesApps)
+ - Added 'Download' button to the Snippets page (Justin DiPierro)
- Fix robots.txt disallowing access to groups starting with "s" (Matt Harrison)
- Close open merge request without source project (Katarzyna Kobierska Ula Budziszewska)
- Fix that manual jobs would no longer block jobs in the next stage. !6604
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
diff --git a/app/views/snippets/show.html.haml b/app/views/snippets/show.html.haml
index cd89155c616..27d7a6c5bb6 100644
--- a/app/views/snippets/show.html.haml
+++ b/app/views/snippets/show.html.haml
@@ -9,6 +9,7 @@
.file-actions
= clipboard_button(clipboard_target: ".blob-content[data-blob-id='#{@snippet.id}']")
= link_to 'Raw', raw_snippet_path(@snippet), class: "btn btn-sm", target: "_blank"
+ = link_to 'Download', download_snippet_path(@snippet), class: "btn btn-sm"
= render 'shared/snippets/blob'
= render 'award_emoji/awards_block', awardable: @snippet, inline: true \ No newline at end of file
diff --git a/config/routes/snippets.rb b/config/routes/snippets.rb
index 1949f215c66..3ca096f31ba 100644
--- a/config/routes/snippets.rb
+++ b/config/routes/snippets.rb
@@ -1,6 +1,7 @@
resources :snippets, concerns: :awardable do
member do
get 'raw'
+ get 'download'
end
end