diff --git a/mayan/apps/document_states/api_views.py b/mayan/apps/document_states/api_views.py index 1c3599f9ad..9fa335d69c 100644 --- a/mayan/apps/document_states/api_views.py +++ b/mayan/apps/document_states/api_views.py @@ -5,7 +5,7 @@ from django.shortcuts import get_object_or_404 from rest_framework import generics from acls.models import AccessControlList -from documents.models import Document +from documents.models import Document, DocumentType from documents.permissions import permission_document_type_view from rest_api.filters import MayanObjectPermissionsFilter from rest_api.permissions import MayanPermission @@ -25,6 +25,29 @@ from .serializers import ( ) +class APIDocumentTypeWorkflowListView(generics.ListAPIView): + serializer_class = WorkflowSerializer + + def get(self, *args, **kwargs): + """ + Returns a list of all the document type workflows. + """ + return super(APIDocumentTypeWorkflowListView, self).get(*args, **kwargs) + + def get_document_type(self): + document_type = get_object_or_404(DocumentType, pk=self.kwargs['pk']) + + AccessControlList.objects.check_access( + permissions=permission_workflow_view, user=self.request.user, + obj=document_type + ) + + return document_type + + def get_queryset(self): + return self.get_document_type().workflows.all() + + class APIWorkflowDocumentTypeList(generics.ListCreateAPIView): filter_backends = (MayanObjectPermissionsFilter,) mayan_object_permissions = { diff --git a/mayan/apps/document_states/tests/test_api.py b/mayan/apps/document_states/tests/test_api.py index fe75a90c25..d684f3e36e 100644 --- a/mayan/apps/document_states/tests/test_api.py +++ b/mayan/apps/document_states/tests/test_api.py @@ -187,6 +187,19 @@ class WorkflowAPITestCase(BaseAPITestCase): workflow.refresh_from_db() self.assertEqual(workflow.label, TEST_WORKFLOW_LABEL_EDITED) + def test_document_type_workflow_list(self): + workflow = self._create_workflow() + workflow.document_types.add(self.document_type) + + response = self.client.get( + reverse( + 'rest_api:documenttype-workflow-list', + args=(self.document_type.pk,) + ), + ) + + self.assertEqual(response.data['results'][0]['label'], workflow.label) + @override_settings(OCR_AUTO_OCR=False) class WorkflowStatesAPITestCase(BaseAPITestCase): diff --git a/mayan/apps/document_states/urls.py b/mayan/apps/document_states/urls.py index 8e91c09274..b2dacd6293 100644 --- a/mayan/apps/document_states/urls.py +++ b/mayan/apps/document_states/urls.py @@ -3,10 +3,10 @@ from __future__ import unicode_literals from django.conf.urls import url from .api_views import ( - APIWorkflowDocumentTypeList, APIWorkflowDocumentTypeView, - APIWorkflowInstanceListView, APIWorkflowInstanceView, - APIWorkflowInstanceLogEntryListView, APIWorkflowListView, - APIWorkflowStateListView, APIWorkflowStateView, + APIDocumentTypeWorkflowListView, APIWorkflowDocumentTypeList, + APIWorkflowDocumentTypeView, APIWorkflowInstanceListView, + APIWorkflowInstanceView, APIWorkflowInstanceLogEntryListView, + APIWorkflowListView, APIWorkflowStateListView, APIWorkflowStateView, APIWorkflowTransitionListView, APIWorkflowTransitionView, APIWorkflowView ) from .views import ( @@ -149,4 +149,9 @@ api_urls = [ APIWorkflowInstanceLogEntryListView.as_view(), name='workflowinstancelogentry-list' ), + url( + r'^document_type/(?P[0-9]+)/workflows/$', + APIDocumentTypeWorkflowListView.as_view(), + name='documenttype-workflow-list' + ), ]