2016-07-20 12:41:26 -04:00
|
|
|
module LfsHelper
|
2016-09-26 18:21:38 -04:00
|
|
|
include Gitlab::Routing.url_helpers
|
2016-11-02 17:50:44 -04:00
|
|
|
|
2016-08-10 10:48:21 -04:00
|
|
|
def require_lfs_enabled!
|
2016-07-20 12:41:26 -04:00
|
|
|
return if Gitlab.config.lfs.enabled
|
|
|
|
|
|
|
|
render(
|
|
|
|
json: {
|
|
|
|
message: 'Git LFS is not enabled on this GitLab server, contact your admin.',
|
2016-09-26 18:21:38 -04:00
|
|
|
documentation_url: help_url,
|
2016-07-20 12:41:26 -04:00
|
|
|
},
|
|
|
|
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?
|
2016-08-24 18:08:23 -04:00
|
|
|
return false unless project.lfs_enabled?
|
|
|
|
|
2016-11-02 17:50:44 -04:00
|
|
|
ci? || lfs_deploy_token? || user_can_download_code? || build_can_download_code?
|
2016-08-08 06:01:25 -04:00
|
|
|
end
|
|
|
|
|
2016-11-10 21:04:00 -05:00
|
|
|
def objects
|
|
|
|
@objects ||= (params[:objects] || []).to_a
|
|
|
|
end
|
|
|
|
|
2016-09-15 04:34:53 -04:00
|
|
|
def user_can_download_code?
|
2016-09-16 05:06:31 -04:00
|
|
|
has_authentication_ability?(:download_code) && can?(user, :download_code, project)
|
2016-08-08 06:01:25 -04:00
|
|
|
end
|
|
|
|
|
2016-09-15 04:34:53 -04:00
|
|
|
def build_can_download_code?
|
2016-09-16 05:06:31 -04:00
|
|
|
has_authentication_ability?(:build_download_code) && can?(user, :build_download_code, project)
|
2016-07-20 12:41:26 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def lfs_upload_access?
|
2016-08-24 18:08:23 -04:00
|
|
|
return false unless project.lfs_enabled?
|
|
|
|
|
2016-09-16 05:06:31 -04:00
|
|
|
has_authentication_ability?(:push_code) && can?(user, :push_code, project)
|
2016-07-20 12:41:26 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def render_lfs_forbidden
|
|
|
|
render(
|
|
|
|
json: {
|
|
|
|
message: 'Access forbidden. Check your access level.',
|
2016-09-26 18:21:38 -04:00
|
|
|
documentation_url: help_url,
|
2016-07-20 12:41:26 -04:00
|
|
|
},
|
|
|
|
content_type: "application/vnd.git-lfs+json",
|
|
|
|
status: 403
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_lfs_not_found
|
|
|
|
render(
|
|
|
|
json: {
|
|
|
|
message: 'Not found.',
|
2016-09-26 18:21:38 -04:00
|
|
|
documentation_url: help_url,
|
2016-07-20 12:41:26 -04:00
|
|
|
},
|
|
|
|
content_type: "application/vnd.git-lfs+json",
|
|
|
|
status: 404
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def storage_project
|
|
|
|
@storage_project ||= begin
|
|
|
|
result = project
|
|
|
|
|
2016-07-22 10:40:22 -04:00
|
|
|
loop do
|
|
|
|
break unless result.forked?
|
2016-07-20 12:41:26 -04:00
|
|
|
result = result.forked_from_project
|
|
|
|
end
|
|
|
|
|
|
|
|
result
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|