diff options
author | Rémy Coutable <remy@rymai.me> | 2016-08-11 14:36:40 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-08-11 14:36:40 +0000 |
commit | 4c29c25497c9a20a5d1f57cd287123cd41edad96 (patch) | |
tree | a9eda345190f046c80456e4979973f3489ddfa21 /app/helpers | |
parent | 7e9b41896d8c2ffae36152401f35479b39297e78 (diff) | |
parent | 6e6ad3e2fc386044134cbb33395cceb97e913fa0 (diff) | |
download | gitlab-ce-4c29c25497c9a20a5d1f57cd287123cd41edad96.tar.gz |
Merge branch 'remove-grack-lfs' into 'master'
Remove Grack::Auth: part 2 (LFS)
Deprecate Grack::Auth and handle LFS in Rails controllers under the Project namespace.
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/14501
See merge request !5369
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/lfs_helper.rb | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/app/helpers/lfs_helper.rb b/app/helpers/lfs_helper.rb new file mode 100644 index 00000000000..eb651e3687e --- /dev/null +++ b/app/helpers/lfs_helper.rb @@ -0,0 +1,67 @@ +module LfsHelper + def require_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 + + loop do + break unless result.forked? + result = result.forked_from_project + end + + result + end + end +end |