Commit a9ca1e41 authored by sebastien letort's avatar sebastien letort

APIDownloadView correction. Url match request, View returns a json error, and...

APIDownloadView correction. Url match request, View returns a json error, and auth view allow to reach api/v1/datastore, not only /datastore.
The idea is to make the code explains that the file should be served by nginx. It has to be accessible in http mode (dev) only.
parent 52f58ccf
......@@ -7,5 +7,5 @@ app_name = 'api'
urlpatterns = [
url(r'^jobs$', views.jobs, name='jobs'),
url(r'^jobs/(?P<pk>\d+)', views.APIJobView.as_view(), name='job'),
url(r'^datastore/(?P<pk>\d+)/(.*)/(.*)', views.APIDownloadView.as_view(), name='download'),
url(r'^datastore/(?P<pk>\d+)/(.*)', views.APIDownloadView.as_view(), name='download'),
]
......@@ -96,6 +96,6 @@ def jobs(request):
class APIDownloadView(JobAuthMixin, View):
def get(self, request, *args, **kwargs):
jobid = args[0]
filename = args[1]
return redirect("/datastore/%s/%s" % (jobid, filename))
log.debug("ADV !")
msg = "The file should be delivered by Nginx, so you should not be able to view this message !"
return JsonResponse({'error': msg}, status=404)
......@@ -1506,7 +1506,7 @@ def auth(request):
return HttpResponse(status=401)
# find the relevant job
mo = re.match(r'/datastore/(\d+)/', request.META['HTTP_X_ORIGINAL_URI'])
mo = re.search(r'/datastore/(\d+)/', request.META['HTTP_X_ORIGINAL_URI'])
if mo:
job = Job.objects.filter(id=int(mo.group(1))).first()
if job is not None and job.user == user:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment