mirror of
https://github.com/ansible/awx.git
synced 2026-05-11 11:27:36 -02:30
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:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user