mirror of
https://github.com/ansible/awx.git
synced 2026-05-09 10:27:37 -02:30
allow credential_id to job template launch. Funnel credential_id into credential.
This commit is contained in:
@@ -1445,6 +1445,9 @@ class JobTemplateLaunch(RetrieveAPIView, GenericAPIView):
|
|||||||
if not request.user.can_access(self.model, 'start', obj):
|
if not request.user.can_access(self.model, 'start', obj):
|
||||||
raise PermissionDenied()
|
raise PermissionDenied()
|
||||||
|
|
||||||
|
if 'credential' not in request.DATA and 'credential_id' in request.DATA:
|
||||||
|
request.DATA['credential'] = request.DATA['credential_id']
|
||||||
|
|
||||||
serializer = self.serializer_class(data=request.DATA, context={'obj': obj})
|
serializer = self.serializer_class(data=request.DATA, context={'obj': obj})
|
||||||
if not serializer.is_valid():
|
if not serializer.is_valid():
|
||||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|||||||
@@ -482,24 +482,37 @@ class JobTemplateTest(BaseJobTestMixin, django.test.TestCase):
|
|||||||
# Invalid auth can't trigger the launch endpoint
|
# Invalid auth can't trigger the launch endpoint
|
||||||
self.check_invalid_auth(launch_url, {}, methods=('post',))
|
self.check_invalid_auth(launch_url, {}, methods=('post',))
|
||||||
|
|
||||||
|
# Implicit, attached credentials
|
||||||
with self.current_user(self.user_sue):
|
with self.current_user(self.user_sue):
|
||||||
response = self.post(launch_url, {}, expect=202)
|
response = self.post(launch_url, {}, expect=202)
|
||||||
j = Job.objects.get(pk=response['job'])
|
j = Job.objects.get(pk=response['job'])
|
||||||
self.assertTrue(j.status == 'new')
|
self.assertTrue(j.status == 'new')
|
||||||
|
|
||||||
|
# Explicit, override credentials
|
||||||
with self.current_user(self.user_sue):
|
with self.current_user(self.user_sue):
|
||||||
response = self.post(launch_url, {'credential': self.cred_doug.pk}, expect=202)
|
response = self.post(launch_url, {'credential': self.cred_doug.pk}, expect=202)
|
||||||
j = Job.objects.get(pk=response['job'])
|
j = Job.objects.get(pk=response['job'])
|
||||||
self.assertTrue(j.status == 'new')
|
self.assertTrue(j.status == 'new')
|
||||||
|
self.assertEqual(j.credential.pk, self.cred_doug.pk)
|
||||||
|
|
||||||
|
# Explicit, override credentials
|
||||||
|
with self.current_user(self.user_sue):
|
||||||
|
response = self.post(launch_url, {'credential_id': self.cred_doug.pk}, expect=202)
|
||||||
|
j = Job.objects.get(pk=response['job'])
|
||||||
|
self.assertTrue(j.status == 'new')
|
||||||
|
self.assertEqual(j.credential.pk, self.cred_doug.pk)
|
||||||
|
|
||||||
# Can't launch a job template without a credential defined (or if we
|
# Can't launch a job template without a credential defined (or if we
|
||||||
# pass an invalid/inactive credential value).
|
# pass an invalid/inactive credential value).
|
||||||
with self.current_user(self.user_sue):
|
with self.current_user(self.user_sue):
|
||||||
response = self.post(no_launch_url, {}, expect=400)
|
response = self.post(no_launch_url, {}, expect=400)
|
||||||
response = self.post(no_launch_url, {'credential': 0}, expect=400)
|
response = self.post(no_launch_url, {'credential': 0}, expect=400)
|
||||||
|
response = self.post(no_launch_url, {'credential_id': 0}, expect=400)
|
||||||
response = self.post(no_launch_url, {'credential': 'one'}, expect=400)
|
response = self.post(no_launch_url, {'credential': 'one'}, expect=400)
|
||||||
|
response = self.post(no_launch_url, {'credential_id': 'one'}, expect=400)
|
||||||
self.cred_doug.mark_inactive()
|
self.cred_doug.mark_inactive()
|
||||||
response = self.post(no_launch_url, {'credential': self.cred_doug.pk}, expect=400)
|
response = self.post(no_launch_url, {'credential': self.cred_doug.pk}, expect=400)
|
||||||
|
response = self.post(no_launch_url, {'credential_id': self.cred_doug.pk}, expect=400)
|
||||||
|
|
||||||
# Job Templates without projects can not be launched
|
# Job Templates without projects can not be launched
|
||||||
with self.current_user(self.user_sue):
|
with self.current_user(self.user_sue):
|
||||||
|
|||||||
Reference in New Issue
Block a user