Skip to content

Commit

Permalink
Add approve/deny endpoints, fix some typos
Browse files Browse the repository at this point in the history
  • Loading branch information
beeankha committed Jul 10, 2019
1 parent ba2bafb commit 9c29161
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 18 deletions.
12 changes: 11 additions & 1 deletion awx/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3370,11 +3370,18 @@ class Meta:
fields = ('can_cancel',)


class WorkflowApprovalViewSerializer(UnifiedJobSerializer):

class Meta:
model = WorkflowApproval
fields = []


class WorkflowApprovalSerializer(UnifiedJobSerializer):

class Meta:
model = WorkflowApproval
fields = ('*', '-controller_node', '-execution_node',)
fields = (['*', '-controller_node', '-execution_node',])

def get_related(self, obj):
res = super(WorkflowApprovalSerializer, self).get_related(obj)
Expand All @@ -3383,9 +3390,12 @@ def get_related(self, obj):
res['workflow_approval_template'] = self.reverse('api:workflow_approval_template_detail',
kwargs={'pk': obj.workflow_approval_template.pk})
res['notifications'] = self.reverse('api:workflow_approval_notifications_list', kwargs={'pk': obj.pk})
res['approve'] = self.reverse('api:workflow_approval_approve', kwargs={'pk': obj.pk})
res['deny'] = self.reverse('api:workflow_approval_deny', kwargs={'pk': obj.pk})
return res



class WorkflowApprovalListSerializer(WorkflowApprovalSerializer, UnifiedJobListSerializer):

class Meta:
Expand Down
6 changes: 4 additions & 2 deletions awx/api/urls/workflow_approval.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
from awx.api.views import (
WorkflowApprovalList,
WorkflowApprovalDetail,
WorkflowApprovalApprove,
WorkflowApprovalDeny,
WorkflowApprovalNotificationsList,
)


urls = [
url(r'^$', WorkflowApprovalList.as_view(), name='workflow_approval_list'),
url(r'^(?P<pk>[0-9]+)/$', WorkflowApprovalDetail.as_view(), name='workflow_approval_detail'),
url(r'^(?P<pk>[0-9]+)/approve/$', WorkflowApprovalDetail.as_view(), name='approved_workflow'),
url(r'^(?P<pk>[0-9]+)/reject/$', WorkflowApprovalDetail.as_view(), name='rejected_workflow'),
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]+)/notifications/$', WorkflowApprovalNotificationsList.as_view(), name='workflow_approval_notifications_list'),
]

Expand Down
8 changes: 4 additions & 4 deletions awx/api/urls/workflow_approval_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from django.conf.urls import url

from awx.api.views import (
WorfklowApprovalTemplateList,
WorfklowApprovalTemplateDetail,
WorkflowApprovalTemplateList,
WorkflowApprovalTemplateDetail,
WorkflowApprovalTemplateJobsList,
WorkflowApprovalTemplateNotificationTemplatesErrorList,
WorkflowApprovalTemplateNotificationTemplatesStartedList,
Expand All @@ -14,8 +14,8 @@


urls = [
url(r'^$', WorfklowApprovalTemplateList.as_view(), name='workflow_approval_template_list'),
url(r'^(?P<pk>[0-9]+)/$', WorfklowApprovalTemplateDetail.as_view(), name='workflow_approval_template_detail'),
url(r'^$', WorkflowApprovalTemplateList.as_view(), name='workflow_approval_template_list'),
url(r'^(?P<pk>[0-9]+)/$', WorkflowApprovalTemplateDetail.as_view(), name='workflow_approval_template_detail'),
url(r'^(?P<pk>[0-9]+)/approvals/$', WorkflowApprovalTemplateJobsList.as_view(), name='workflow_approval_template_jobs_list'),
url(r'^(?P<pk>[0-9]+)/notification_templates_started/$', WorkflowApprovalTemplateNotificationTemplatesStartedList.as_view(),
name='workflow_approval_template_notification_templates_started_list'),
Expand Down
29 changes: 22 additions & 7 deletions awx/api/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4407,18 +4407,13 @@ def get_queryset(self):
setattr(this_module, name, view)


class WorfklowApprovalTemplateList(ListAPIView):
class WorkflowApprovalTemplateList(ListCreateAPIView):

model = models.WorkflowApprovalTemplate
serializer_class = serializers.WorkflowApprovalTemplateSerializer

def get(self, request, *args, **kwargs):
if not request.user.is_superuser and not request.user.is_system_auditor:
raise PermissionDenied(_("Superuser privileges needed."))
return super(WorfklowApprovalTemplateList, self).get(request, *args, **kwargs)


class WorfklowApprovalTemplateDetail(RetrieveAPIView):
class WorkflowApprovalTemplateDetail(RelatedJobsPreventDeleteMixin, RetrieveUpdateDestroyAPIView):

model = models.WorkflowApprovalTemplate
serializer_class = serializers.WorkflowApprovalTemplateSerializer
Expand Down Expand Up @@ -4472,6 +4467,26 @@ class WorkflowApprovalDetail(UnifiedJobDeletionMixin, RetrieveDestroyAPIView):
serializer_class = serializers.WorkflowApprovalSerializer


class WorkflowApprovalApprove(RetrieveAPIView):
model = models.WorkflowApproval
serializer_class = serializers.WorkflowApprovalViewSerializer

def post(self, request, *args, **kwargs):
obj = self.get_object()
obj.approve()
return Response(status=status.HTTP_202_ACCEPTED)


class WorkflowApprovalDeny(RetrieveAPIView):
model = models.WorkflowApproval
serializer_class = serializers.WorkflowApprovalViewSerializer

def post(self, request, *args, **kwargs):
obj = self.get_object()
obj.deny()
return Response(status=status.HTTP_202_ACCEPTED)


class WorkflowApprovalNotificationsList(SubListAPIView):

model = models.Notification
Expand Down
2 changes: 1 addition & 1 deletion awx/main/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -2807,7 +2807,7 @@ def can_use(self, obj):
return True

def filtered_queryset(self):
return self.model.objects.all()
return self.model.filter(workflowjobtemplatenodes__workflow_job_template=WorkflowJobTemplate.accessible_pk_qs(self.user, 'read_role'))


for cls in BaseAccess.__subclasses__():
Expand Down
6 changes: 3 additions & 3 deletions awx/main/models/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,10 +648,10 @@ def approve(self, request=None):
self.status = 'successful'
self.save()
schedule_task_manager()
return reverse('api:approved_workflow', kwargs={'pk': self.pk}, request=request)
return reverse('api:workflow_approval_approve', kwargs={'pk': self.pk}, request=request)

def reject(self, request=None):
def deny(self, request=None):
self.status = 'failed'
self.save()
schedule_task_manager()
return reverse('api:rejected_workflow', kwargs={'pk': self.pk}, request=request)
return reverse('api:workflow_approval_deny', kwargs={'pk': self.pk}, request=request)

0 comments on commit 9c29161

Please sign in to comment.