summaryrefslogtreecommitdiff
path: root/app/helpers
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2016-07-20 18:41:26 +0200
committerJacob Vosmaer <jacob@gitlab.com>2016-07-22 17:54:04 +0200
commit0d9752446d8e2b3b4fdb37eb8ec75c5e5f996f1c (patch)
treee164e0781a8e8bf2076503c504dacff670136554 /app/helpers
parent033e5423a2594e08a7ebcd2379bd2331f4c39032 (diff)
downloadgitlab-ce-0d9752446d8e2b3b4fdb37eb8ec75c5e5f996f1c.tar.gz
Add LFS controllers
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/lfs_helper.rb66
1 files changed, 66 insertions, 0 deletions
diff --git a/app/helpers/lfs_helper.rb b/app/helpers/lfs_helper.rb
new file mode 100644
index 00000000000..6146a2ad849
--- /dev/null
+++ b/app/helpers/lfs_helper.rb
@@ -0,0 +1,66 @@
+module LfsHelper
+ def lfs_enabled!
+ return if Gitlab.config.lfs.enabled
+
+ render(
+ json: {
+ message: 'Git LFS is not enabled on this GitLab server, contact your admin.',
+ documentation_url: "#{Gitlab.config.gitlab.url}/help",
+ },
+ status: 501
+ )
+ end
+
+ def lfs_check_access!
+ return if download_request? && lfs_download_access?
+ return if upload_request? && lfs_upload_access?
+
+ if project.public? || (user && user.can?(:read_project, project))
+ render_lfs_forbidden
+ else
+ render_lfs_not_found
+ end
+ end
+
+ def lfs_download_access?
+ project.public? || ci? || (user && user.can?(:download_code, project))
+ end
+
+ def lfs_upload_access?
+ user && user.can?(:push_code, project)
+ end
+
+ def render_lfs_forbidden
+ render(
+ json: {
+ message: 'Access forbidden. Check your access level.',
+ documentation_url: "#{Gitlab.config.gitlab.url}/help",
+ },
+ content_type: "application/vnd.git-lfs+json",
+ status: 403
+ )
+ end
+
+ def render_lfs_not_found
+ render(
+ json: {
+ message: 'Not found.',
+ documentation_url: "#{Gitlab.config.gitlab.url}/help",
+ },
+ content_type: "application/vnd.git-lfs+json",
+ status: 404
+ )
+ end
+
+ def storage_project
+ @storage_project ||= begin
+ result = project
+
+ while result.forked? do
+ result = result.forked_from_project
+ end
+
+ result
+ end
+ end
+end