Commit 52f58ccf authored by BAIRE Anthony's avatar BAIRE Anthony

Merge branch 'minor_refactoring' into 'django'

Minor refactoring

See merge request !168
parents cd0e8ed4 fe432f46
Pipeline #79357 passed with stages
in 2 minutes and 23 seconds
......@@ -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, name='download'),
url(r'^datastore/(?P<pk>\d+)/(.*)/(.*)', views.APIDownloadView.as_view(), name='download'),
]
......@@ -58,6 +58,10 @@ def jobs(request):
if not app:
return JsonResponse({'error': 'Application not found'}, status=404)
if app.get_webapp_version() is None:
log.debug('No usable versions')
return JsonResponse({'error': "This app is not yet published"}, status=404)
queue = app.job_queue
if 'job[queue]' in request.POST:
try:
......@@ -67,9 +71,6 @@ def jobs(request):
log.info("Job submit by user %s", user)
job = Job.objects.create(param=request.POST.get('job[param]', ''), queue=queue, webapp=app, user=user)
if app.get_webapp_version() is None:
log.debug('No usable versions')
return JsonResponse({'error': "This app is not yet published"}, status=404)
job.version = app.get_webapp_version().number # TODO: add version selection in the api
upload_data(request.FILES.values(), job)
......
......@@ -97,7 +97,11 @@ class JobAuthMixin(AllgoValidAccountMixin, UserPassesTestMixin):
if user is None:
return False
self.raise_exception = True # to return a 403
job = Job.objects.filter(pk=self.kwargs['pk']).first()
try:
job = Job.objects.get(id=self.kwargs['pk'])
except Job.DoesNotExist:
return False
return user.is_superuser or user == getattr(job, "user", ())
def handle_no_permission(self):
......
......@@ -307,6 +307,15 @@ class Webapp(TimeStampModel):
query = query.filter(number=number)
return query.order_by("-state", "-id").first()
def get_sandbox_state(self):
""""""
for i,s in self.SANDBOX_STATE_CHOICES:
if i == self.sandbox_state:
return i,s
msg = "The current state {} is not defined in the model." \
.format(self.sandbox_state)
raise ValueError(msg)
class WebappParameter(TimeStampModel):
......
......@@ -721,7 +721,7 @@ class WebappSandboxPanel(UserAccessMixin, TemplateView):
messages.success(request, "stopping sandbox %r" % webapp.name)
log.debug("new sandbox state: %r -> %r",
webapp.docker_name, webapp.sandbox_state)
webapp.docker_name, webapp.get_sandbox_state())
# NOTE: we return a 302 redirect to the same page (instead of rendering
# it directly) to force the browser to make a separate GET request.
......
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