Implement /launch endpoint on job template

Partial implementation of:

https://trello.com/c/7uXHs7ze/14-require-admin-to-be-able-to-run-a-job-without-a-job-template
This commit is contained in:
Matthew Jones
2014-09-04 13:25:21 -04:00
parent e48309b6aa
commit 58b71ca9f9
6 changed files with 85 additions and 1 deletions

View File

@@ -1337,6 +1337,31 @@ class JobTemplateDetail(RetrieveUpdateDestroyAPIView):
model = JobTemplate
serializer_class = JobTemplateSerializer
class JobTemplateLaunch(GenericAPIView):
model = JobTemplate
def get(self, request, *args, **kwargs):
obj = self.get_object()
data = {}
data['can_start_without_user_input'] = obj.can_start_without_user_input()
data['passwords_needed_to_start'] = obj.passwords_needed_to_start
data['ask_variables_on_launch'] = obj.ask_variables_on_launch
return Response(data)
def post(self, request, *args, **obj):
obj = self.get_object()
if not request.user.can_access(self.model, 'start', obj):
raise PermissionDenied()
new_job = obj.create_unified_job()
result = new_job.signal_start(**request.DATA)
if not result:
data = dict(passwords_needed_to_start=obj.passwords_needed_to_start)
return Response(data, status=status.HTTP_400_BAD_REQUEST)
else:
data = dict(job=new_job.id)
return Response(data, status=status.HTTP_202_ACCEPTED)
class JobTemplateSchedulesList(SubListCreateAPIView):
view_name = "Job Template Schedules"