summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKia Mei Somabes <kssomabes@up.edu.ph>2018-07-13 09:24:11 +0800
committerKia Mei Somabes <kssomabes@up.edu.ph>2018-07-13 09:33:35 +0800
commit1e0f0de30253cf20533fe4002272e3e3861b3883 (patch)
tree86a51b02976b9469066a0a46ad8b90a5c6f16cdd
parent9f57ae11e935d2a8a2b175d8382ed87020727845 (diff)
downloadgitlab-ce-1e0f0de30253cf20533fe4002272e3e3861b3883.tar.gz
Refactor code for single file download in repository
-rw-r--r--app/controllers/projects/raw_controller.rb2
-rw-r--r--app/helpers/blob_helper.rb23
-rw-r--r--app/helpers/workhorse_helper.rb4
-rw-r--r--app/views/projects/artifacts/file.html.haml2
-rw-r--r--changelogs/unreleased/23705-add-single-file-download-in-repo.yml4
5 files changed, 17 insertions, 18 deletions
diff --git a/app/controllers/projects/raw_controller.rb b/app/controllers/projects/raw_controller.rb
index f6bfe4a5747..1cba0011304 100644
--- a/app/controllers/projects/raw_controller.rb
+++ b/app/controllers/projects/raw_controller.rb
@@ -18,7 +18,7 @@ class Projects::RawController < Projects::ApplicationController
if @blob.stored_externally?
send_lfs_object
else
- send_git_blob @repository, @blob, params[:inline]
+ send_git_blob @repository, @blob, inline: (params[:inline] != 'false')
end
else
render_404
diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb
index 0fec8e891b7..3ba49277b5e 100644
--- a/app/helpers/blob_helper.rb
+++ b/app/helpers/blob_helper.rb
@@ -114,22 +114,22 @@ module BlobHelper
icon("#{file_type_icon_class('file', mode, name)} fw")
end
- def blob_raw_url(only_path: false, inline: nil)
+ def blob_raw_url(**kwargs)
if @build && @entry
- raw_project_job_artifacts_url(@project, @build, path: @entry.path, only_path: only_path)
+ raw_project_job_artifacts_url(@project, @build, path: @entry.path, **kwargs)
elsif @snippet
if @snippet.project_id
- raw_project_snippet_url(@project, @snippet, only_path: only_path)
+ raw_project_snippet_url(@project, @snippet, **kwargs)
else
- raw_snippet_url(@snippet, only_path: only_path)
+ raw_snippet_url(@snippet, **kwargs)
end
elsif @blob
- project_raw_url(@project, @id, only_path: only_path, inline: inline)
+ project_raw_url(@project, @id, **kwargs)
end
end
- def blob_raw_path
- blob_raw_url(only_path: true)
+ def blob_raw_path(**kwargs)
+ blob_raw_url(**kwargs, only_path: true)
end
# SVGs can contain malicious JavaScript; only include whitelisted
@@ -226,16 +226,15 @@ module BlobHelper
def open_raw_blob_button(blob)
return if blob.empty?
- 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
+ return if blob.raw_binary? || blob.stored_externally?
+ title = 'Open raw'
+ link_to icon('file-code-o'), blob_raw_path, class: 'btn btn-sm has-tooltip', target: '_blank', rel: 'noopener noreferrer', title: title, data: { container: 'body' }
end
def download_blob_button(blob)
return if blob.empty?
title = 'Download'
- 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' }
+ link_to sprite_icon('download'), blob_raw_path(inline: false), 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 980d07c8800..fd1d78bd9b8 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, inline)
+ def send_git_blob(repository, blob, inline: true)
headers.store(*Gitlab::Workhorse.send_git_blob(repository, blob))
- inline ? (headers['Content-Disposition'] = 'inline') : (headers['Content-Disposition'] = 'attachment')
+ headers['Content-Disposition'] = inline ? 'inline' : 'attachment'
headers['Content-Type'] = safe_content_type(blob)
render plain: ""
end
diff --git a/app/views/projects/artifacts/file.html.haml b/app/views/projects/artifacts/file.html.haml
index aac7a1870df..f7174d6b2c6 100644
--- a/app/views/projects/artifacts/file.html.haml
+++ b/app/views/projects/artifacts/file.html.haml
@@ -27,6 +27,6 @@
.btn-group{ role: "group" }<
= copy_blob_source_button(blob)
- = open_raw_blob_button(blob)
+ = download_blob_button(blob)
= render 'projects/blob/content', blob: blob
diff --git a/changelogs/unreleased/23705-add-single-file-download-in-repo.yml b/changelogs/unreleased/23705-add-single-file-download-in-repo.yml
index a3ec853f03c..f156bfb1101 100644
--- a/changelogs/unreleased/23705-add-single-file-download-in-repo.yml
+++ b/changelogs/unreleased/23705-add-single-file-download-in-repo.yml
@@ -1,5 +1,5 @@
---
title: Add download button for single file (including raw files) in repository
-merge_request:
-author:
+merge_request: 20480
+author: Kia Mei Somabes
type: added