From 7d827e27521ec36d0acc56c52ed7875af60da0b7 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Tue, 2 Mar 2021 10:30:41 +0900 Subject: [PATCH] Add project delete component --- app/api/tests/test_api.py | 6 --- app/api/views/project.py | 15 +++++- frontend/components/project/FormDelete.vue | 58 ++++++++++++++++++++++ frontend/pages/projects/index.vue | 41 ++++++++++++++- 4 files changed, 111 insertions(+), 9 deletions(-) create mode 100644 frontend/components/project/FormDelete.vue diff --git a/app/api/tests/test_api.py b/app/api/tests/test_api.py index 5b95b746..a6083451 100644 --- a/app/api/tests/test_api.py +++ b/app/api/tests/test_api.py @@ -138,12 +138,6 @@ class TestProjectListAPI(APITestCase): self.assertTrue(response.json().get('collaborative_annotation')) self.assertTrue(response.json().get('randomize_document_order')) - def test_disallows_project_member_to_create_project(self): - self.client.login(username=self.main_project_member_name, - password=self.main_project_member_pass) - response = self.client.post(self.url, format='json', data=self.data) - self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) - @classmethod def doCleanups(cls): remove_all_role_mappings() diff --git a/app/api/views/project.py b/app/api/views/project.py index 5516c80f..4c8333e1 100644 --- a/app/api/views/project.py +++ b/app/api/views/project.py @@ -1,5 +1,7 @@ -from rest_framework import generics +from django.conf import settings +from rest_framework import generics, status from rest_framework.permissions import IsAuthenticated +from rest_framework.response import Response from ..models import Project from ..permissions import IsInProjectReadOnlyOrAdmin @@ -9,7 +11,7 @@ from ..serializers import ProjectPolymorphicSerializer, ProjectSerializer class ProjectList(generics.ListCreateAPIView): serializer_class = ProjectPolymorphicSerializer pagination_class = None - permission_classes = [IsAuthenticated & IsInProjectReadOnlyOrAdmin] + permission_classes = [IsAuthenticated] def get_queryset(self): return self.request.user.projects @@ -17,6 +19,15 @@ class ProjectList(generics.ListCreateAPIView): def perform_create(self, serializer): serializer.save(users=[self.request.user]) + def delete(self, request, *args, **kwargs): + delete_ids = request.data['ids'] + Project.objects.filter( + role_mappings__user=self.request.user, + role_mappings__role__name=settings.ROLE_PROJECT_ADMIN, + pk__in=delete_ids + ).delete() + return Response(status=status.HTTP_204_NO_CONTENT) + class ProjectDetail(generics.RetrieveUpdateDestroyAPIView): queryset = Project.objects.all() diff --git a/frontend/components/project/FormDelete.vue b/frontend/components/project/FormDelete.vue new file mode 100644 index 00000000..384af875 --- /dev/null +++ b/frontend/components/project/FormDelete.vue @@ -0,0 +1,58 @@ + + + diff --git a/frontend/pages/projects/index.vue b/frontend/pages/projects/index.vue index 07432cf4..f02e9d59 100644 --- a/frontend/pages/projects/index.vue +++ b/frontend/pages/projects/index.vue @@ -1,6 +1,21 @@