mirror of
https://github.com/ansible/awx.git
synced 2024-10-30 22:21:13 +03:00
Fix flake8 errors, update doc strings, ...
... and return full object details when doing a POST to create new approval nodes.
This commit is contained in:
parent
dd89e46ee6
commit
667fce5012
@ -8,7 +8,6 @@ from awx.api.views import (
|
|||||||
WorkflowApprovalDetail,
|
WorkflowApprovalDetail,
|
||||||
WorkflowApprovalApprove,
|
WorkflowApprovalApprove,
|
||||||
WorkflowApprovalDeny,
|
WorkflowApprovalDeny,
|
||||||
WorkflowApprovalNotificationsList,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -17,7 +16,6 @@ urls = [
|
|||||||
url(r'^(?P<pk>[0-9]+)/$', WorkflowApprovalDetail.as_view(), name='workflow_approval_detail'),
|
url(r'^(?P<pk>[0-9]+)/$', WorkflowApprovalDetail.as_view(), name='workflow_approval_detail'),
|
||||||
url(r'^(?P<pk>[0-9]+)/approve/$', WorkflowApprovalApprove.as_view(), name='workflow_approval_approve'),
|
url(r'^(?P<pk>[0-9]+)/approve/$', WorkflowApprovalApprove.as_view(), name='workflow_approval_approve'),
|
||||||
url(r'^(?P<pk>[0-9]+)/deny/$', WorkflowApprovalDeny.as_view(), name='workflow_approval_deny'),
|
url(r'^(?P<pk>[0-9]+)/deny/$', WorkflowApprovalDeny.as_view(), name='workflow_approval_deny'),
|
||||||
url(r'^(?P<pk>[0-9]+)/notifications/$', WorkflowApprovalNotificationsList.as_view(), name='workflow_approval_notifications_list'),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
__all__ = ['urls']
|
__all__ = ['urls']
|
||||||
|
@ -3018,12 +3018,16 @@ class WorkflowJobTemplateNodeCreateApproval(RetrieveAPIView):
|
|||||||
serializer_class = serializers.WorkflowJobTemplateNodeCreateApprovalSerializer
|
serializer_class = serializers.WorkflowJobTemplateNodeCreateApprovalSerializer
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
serializer = self.get_serializer(data=request.data)
|
obj = self.get_object()
|
||||||
|
serializer = self.get_serializer(instance=obj, data=request.data)
|
||||||
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)
|
||||||
obj = self.get_object()
|
|
||||||
approval_template = obj.create_approval_template(**serializer.validated_data)
|
approval_template = obj.create_approval_template(**serializer.validated_data)
|
||||||
return Response(data={'id':approval_template.pk}, status=status.HTTP_200_OK)
|
data = serializers.WorkflowApprovalTemplateSerializer(
|
||||||
|
approval_template,
|
||||||
|
context=self.get_serializer_context()
|
||||||
|
).data
|
||||||
|
return Response(data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
def check_permissions(self, request):
|
def check_permissions(self, request):
|
||||||
obj = self.get_object().workflow_job_template
|
obj = self.get_object().workflow_job_template
|
||||||
@ -4487,13 +4491,3 @@ class WorkflowApprovalDeny(RetrieveAPIView):
|
|||||||
return Response("This workflow step has already been approved or denied.", status=status.HTTP_400_BAD_REQUEST)
|
return Response("This workflow step has already been approved or denied.", status=status.HTTP_400_BAD_REQUEST)
|
||||||
obj.deny(request)
|
obj.deny(request)
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
# Placeholder code for approval notification support
|
|
||||||
class WorkflowApprovalNotificationsList(SubListAPIView):
|
|
||||||
|
|
||||||
model = models.Notification
|
|
||||||
serializer_class = serializers.NotificationSerializer
|
|
||||||
parent_model = models.WorkflowApproval
|
|
||||||
relationship = 'notifications'
|
|
||||||
search_fields = ('subject', 'notification_type', 'body',)
|
|
||||||
|
@ -134,7 +134,7 @@ def check_user_access_with_errors(user, model_class, action, *args, **kwargs):
|
|||||||
access_instance = access_class(user, save_messages=True)
|
access_instance = access_class(user, save_messages=True)
|
||||||
access_method = getattr(access_instance, 'can_%s' % action, None)
|
access_method = getattr(access_instance, 'can_%s' % action, None)
|
||||||
result = access_method(*args, **kwargs)
|
result = access_method(*args, **kwargs)
|
||||||
logger.error('%s.%s %r returned %r', access_instance.__class__.__name__,
|
logger.debug('%s.%s %r returned %r', access_instance.__class__.__name__,
|
||||||
access_method.__name__, args, result)
|
access_method.__name__, args, result)
|
||||||
return (result, access_instance.messages)
|
return (result, access_instance.messages)
|
||||||
|
|
||||||
@ -2781,10 +2781,15 @@ class RoleAccess(BaseAccess):
|
|||||||
|
|
||||||
class WorkflowApprovalAccess(BaseAccess):
|
class WorkflowApprovalAccess(BaseAccess):
|
||||||
'''
|
'''
|
||||||
I can approve workflows when:
|
A user can create an approval template if they are a superuser, an org admin
|
||||||
- I'm authenticated
|
of the org connected to the workflow, or if they are assigned as admins to
|
||||||
I can create when:
|
the workflow.
|
||||||
- I'm a superuser:
|
|
||||||
|
A user can approve a workflow when they are:
|
||||||
|
- a superuser
|
||||||
|
- a workflow admin
|
||||||
|
- an organization admin
|
||||||
|
- any user who has explicitly been assigned the "approver" role
|
||||||
'''
|
'''
|
||||||
|
|
||||||
model = WorkflowApproval
|
model = WorkflowApproval
|
||||||
@ -2810,10 +2815,15 @@ class WorkflowApprovalAccess(BaseAccess):
|
|||||||
|
|
||||||
class WorkflowApprovalTemplateAccess(BaseAccess):
|
class WorkflowApprovalTemplateAccess(BaseAccess):
|
||||||
'''
|
'''
|
||||||
I can create approval nodes when:
|
A user can create an approval template if they are a superuser, an org admin
|
||||||
-
|
of the org connected to the workflow, or if they are assigned as admins to
|
||||||
I can approve workflows when:
|
the workflow.
|
||||||
-
|
|
||||||
|
A user can approve a workflow when they are:
|
||||||
|
- a superuser
|
||||||
|
- a workflow admin
|
||||||
|
- an organization admin
|
||||||
|
- any user who has explicitly been assigned the "approver" role
|
||||||
'''
|
'''
|
||||||
|
|
||||||
model = WorkflowApprovalTemplate
|
model = WorkflowApprovalTemplate
|
||||||
@ -2821,11 +2831,6 @@ class WorkflowApprovalTemplateAccess(BaseAccess):
|
|||||||
|
|
||||||
@check_superuser
|
@check_superuser
|
||||||
def can_add(self, data):
|
def can_add(self, data):
|
||||||
'''
|
|
||||||
A user can create an approval template if they are a superuser, an org admin
|
|
||||||
of the org connected to the workflow, or if they are assigned as admins to
|
|
||||||
the workflow.
|
|
||||||
'''
|
|
||||||
if data is None: # Hide direct creation in API browser
|
if data is None: # Hide direct creation in API browser
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
|
|
||||||
# Python
|
# Python
|
||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
@ -32,11 +31,10 @@ from awx.main.models.mixins import (
|
|||||||
RelatedJobsMixin,
|
RelatedJobsMixin,
|
||||||
)
|
)
|
||||||
from awx.main.models.jobs import LaunchTimeConfigBase, LaunchTimeConfig, JobTemplate
|
from awx.main.models.jobs import LaunchTimeConfigBase, LaunchTimeConfig, JobTemplate
|
||||||
from awx.main.models.activity_stream import ActivityStream
|
|
||||||
from awx.main.models.credential import Credential
|
from awx.main.models.credential import Credential
|
||||||
from awx.main.redact import REPLACE_STR
|
from awx.main.redact import REPLACE_STR
|
||||||
from awx.main.fields import JSONField
|
from awx.main.fields import JSONField
|
||||||
from awx.main.utils import model_to_dict, schedule_task_manager
|
from awx.main.utils import schedule_task_manager
|
||||||
|
|
||||||
|
|
||||||
from copy import copy
|
from copy import copy
|
||||||
|
Loading…
Reference in New Issue
Block a user