summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorKia Mei Somabes <kssomabes@up.edu.ph>2018-07-12 10:23:00 +0800
committerKia Mei Somabes <kssomabes@up.edu.ph>2018-07-12 10:23:00 +0800
commit9f57ae11e935d2a8a2b175d8382ed87020727845 (patch)
tree87a309a07ce9f1765700bdd062544cb3c9acc398 /app
parent50c128944e5e65fb5124aeb790cc0f1ec06049d3 (diff)
downloadgitlab-ce-9f57ae11e935d2a8a2b175d8382ed87020727845.tar.gz
Set content-disposition header for single file download in repository
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/raw_controller.rb3
-rw-r--r--app/helpers/blob_helper.rb16
-rw-r--r--app/helpers/workhorse_helper.rb4
-rw-r--r--app/views/projects/blob/_header.html.haml5
4 files changed, 13 insertions, 15 deletions
diff --git a/app/controllers/projects/raw_controller.rb b/app/controllers/projects/raw_controller.rb
index 9bc774b7636..f6bfe4a5747 100644
--- a/app/controllers/projects/raw_controller.rb
+++ b/app/controllers/projects/raw_controller.rb
@@ -10,7 +10,6 @@ class Projects::RawController < Projects::ApplicationController
def show
@blob = @repository.blob_at(@commit.id, @path)
-
if @blob
headers['X-Content-Type-Options'] = 'nosniff'
@@ -19,7 +18,7 @@ class Projects::RawController < Projects::ApplicationController
if @blob.stored_externally?
send_lfs_object
else
- send_git_blob @repository, @blob
+ send_git_blob @repository, @blob, params[:inline]
end
else
render_404
diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb
index 16a8764dc41..0fec8e891b7 100644
--- a/app/helpers/blob_helper.rb
+++ b/app/helpers/blob_helper.rb
@@ -114,7 +114,7 @@ module BlobHelper
icon("#{file_type_icon_class('file', mode, name)} fw")
end
- def blob_raw_url(only_path: false)
+ def blob_raw_url(only_path: false, inline: nil)
if @build && @entry
raw_project_job_artifacts_url(@project, @build, path: @entry.path, only_path: only_path)
elsif @snippet
@@ -124,7 +124,7 @@ module BlobHelper
raw_snippet_url(@snippet, only_path: only_path)
end
elsif @blob
- project_raw_url(@project, @id, only_path: only_path)
+ project_raw_url(@project, @id, only_path: only_path, inline: inline)
end
end
@@ -226,16 +226,16 @@ module BlobHelper
def open_raw_blob_button(blob)
return if blob.empty?
- icon = icon('file-code-o')
- title = 'Open raw'
- link_to icon, blob_raw_path, class: 'btn btn-sm has-tooltip', target: '_blank', rel: 'noopener noreferrer', title: title, data: { container: 'body' }
+ unless blob.raw_binary? || blob.stored_externally?
+ title = 'Open raw'
+ link_to icon('file-code-o'), blob_raw_url(:inline => true), class: 'btn btn-sm has-tooltip', target: '_blank', rel: 'noopener noreferrer', title: title, data: { container: 'body' }
+ end
end
- def download_button(blob)
+ def download_blob_button(blob)
return if blob.empty?
- icon = sprite_icon('download')
title = 'Download'
- link_to icon, blob_raw_path, download: '', class: 'btn btn-sm has-tooltip', target: '_blank', rel: 'noopener noreferrer', title: title, data: { container: 'body' }
+ link_to sprite_icon('download'), blob_raw_url, download: @path, class: 'btn btn-sm has-tooltip', target: '_blank', rel: 'noopener noreferrer', title: title, data: { container: 'body' }
end
def blob_render_error_reason(viewer)
diff --git a/app/helpers/workhorse_helper.rb b/app/helpers/workhorse_helper.rb
index a82271ce0ee..980d07c8800 100644
--- a/app/helpers/workhorse_helper.rb
+++ b/app/helpers/workhorse_helper.rb
@@ -2,9 +2,9 @@
# Workhorse will also serve files when using `send_file`.
module WorkhorseHelper
# Send a Git blob through Workhorse
- def send_git_blob(repository, blob)
+ def send_git_blob(repository, blob, inline)
headers.store(*Gitlab::Workhorse.send_git_blob(repository, blob))
- headers['Content-Disposition'] = 'inline'
+ inline ? (headers['Content-Disposition'] = 'inline') : (headers['Content-Disposition'] = 'attachment')
headers['Content-Type'] = safe_content_type(blob)
render plain: ""
end
diff --git a/app/views/projects/blob/_header.html.haml b/app/views/projects/blob/_header.html.haml
index b3ae1734225..84ccd816d80 100644
--- a/app/views/projects/blob/_header.html.haml
+++ b/app/views/projects/blob/_header.html.haml
@@ -7,9 +7,8 @@
.btn-group{ role: "group" }<
= copy_blob_source_button(blob) unless blame
- - if !(blob.raw_binary? || blob.stored_externally?)
- = open_raw_blob_button(blob)
- = download_button(blob)
+ = open_raw_blob_button(blob)
+ = download_blob_button(blob)
= view_on_environment_button(@commit.sha, @path, @environment) if @environment
.btn-group{ role: "group" }<
= render_if_exists 'projects/blob/header_file_locks_link'