Add per document type, workflow list API view. GitLab issue #357, GitLab merge request #!9. cc @jeverling
This commit is contained in:
@@ -6,7 +6,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 permissions import Permission
|
||||
from rest_api.filters import MayanObjectPermissionsFilter
|
||||
@@ -27,6 +27,33 @@ 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'])
|
||||
|
||||
try:
|
||||
Permission.check_permissions(
|
||||
self.request.user, (permission_workflow_view,)
|
||||
)
|
||||
except PermissionDenied:
|
||||
AccessControlList.objects.check_access(
|
||||
permission_workflow_view, self.request.user, 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 = {
|
||||
|
||||
Reference in New Issue
Block a user