mirror of https://github.com/doccano/doccano.git
pythondatasetsactive-learningtext-annotationdatasetnatural-language-processingdata-labelingmachine-learningannotation-tool
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.5 KiB
41 lines
1.5 KiB
from django.shortcuts import get_object_or_404
|
|
from rest_framework import generics, status
|
|
from rest_framework.permissions import IsAuthenticated
|
|
from rest_framework.response import Response
|
|
|
|
from ..models import Project, Role, RoleMapping
|
|
from ..permissions import IsProjectAdmin
|
|
from ..serializers import RoleMappingSerializer, RoleSerializer
|
|
|
|
|
|
class Roles(generics.ListCreateAPIView):
|
|
serializer_class = RoleSerializer
|
|
pagination_class = None
|
|
permission_classes = [IsAuthenticated & IsProjectAdmin]
|
|
queryset = Role.objects.all()
|
|
|
|
|
|
class RoleMappingList(generics.ListCreateAPIView):
|
|
serializer_class = RoleMappingSerializer
|
|
pagination_class = None
|
|
permission_classes = [IsAuthenticated & IsProjectAdmin]
|
|
|
|
def get_queryset(self):
|
|
project = get_object_or_404(Project, pk=self.kwargs['project_id'])
|
|
return project.role_mappings
|
|
|
|
def perform_create(self, serializer):
|
|
project = get_object_or_404(Project, pk=self.kwargs['project_id'])
|
|
serializer.save(project=project)
|
|
|
|
def delete(self, request, *args, **kwargs):
|
|
delete_ids = request.data['ids']
|
|
RoleMapping.objects.filter(pk__in=delete_ids).delete()
|
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
|
|
|
|
|
class RoleMappingDetail(generics.RetrieveUpdateDestroyAPIView):
|
|
queryset = RoleMapping.objects.all()
|
|
serializer_class = RoleMappingSerializer
|
|
lookup_url_kwarg = 'rolemapping_id'
|
|
permission_classes = [IsAuthenticated & IsProjectAdmin]
|