Serve non-html files from storage in commercial
Remove the "if" that checks if we are in community or commercial and
always serve the files from storage (S3 on commercial). The URL
generated will have an AccessKey and Expires arguments.
@@ -276,6 +276,9 @@ def project_download_media(request, project_slug, type_, version_slug):
It should only care about the Version permissions,
not the actual Project permissions.
"""
+
+ # TODO: this check could be done using ``request.has_perm`` instead, to
+ # avoid having different a logic here for auth permissions.
version = get_object_or_404(
Version.objects.public(user=request.user),
project__slug=project_slug,
@@ -291,8 +294,6 @@ def project_download_media(request, project_slug, type_, version_slug):
uip=get_client_ip(request),
)
- if settings.DEFAULT_PRIVACY_LEVEL == 'public' or settings.DEBUG:
-
storage = get_storage_class(settings.RTD_BUILD_MEDIA_STORAGE)()
storage_path = version.project.get_storage_path(
type_=type_, version_slug=version_slug,
@@ -310,28 +311,6 @@ def project_download_media(request, project_slug, type_, version_slug):
)
return HttpResponseRedirect(media_path)
- # Get relative media path
- path = (
- version.project.get_production_media_path(
- type_=type_,
- version_slug=version_slug,
- ).replace(settings.PRODUCTION_ROOT, '/prod_artifacts')
- )
- content_type, encoding = mimetypes.guess_type(path)
- content_type = content_type or 'application/octet-stream'
- response = HttpResponse(content_type=content_type)
- if encoding:
- response['Content-Encoding'] = encoding
- response['X-Accel-Redirect'] = path
- # Include version in filename; this fixes a long-standing bug
- filename = '{}-{}.{}'.format(
- project_slug,
- version_slug,
- path.split('.')[-1],
- )
- response['Content-Disposition'] = 'filename=%s' % filename
- return response
-
def project_versions(request, project_slug):
"""
