Browse Source
Merge pull request #1647 from doccano/enhancement/removeApprovalAPI
Remove unused Approve API
pull/1653/head
Hiroki Nakayama
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with
2 additions and
59 deletions
-
backend/api/tests/api/test_document.py
-
backend/api/urls.py
-
backend/api/views/annotation.py
-
frontend/domain/models/example/exampleRepository.ts
-
frontend/repositories/example/apiDocumentRepository.ts
-
frontend/services/application/example/exampleApplicationService.ts
|
|
@ -168,24 +168,3 @@ class TestExampleDetail(CRUDMixin): |
|
|
|
|
|
|
|
def test_denies_non_project_member_to_delete_doc(self): |
|
|
|
self.assert_delete(self.non_member, status.HTTP_403_FORBIDDEN) |
|
|
|
|
|
|
|
|
|
|
|
class TestApproveLabelsAPI(CRUDMixin): |
|
|
|
|
|
|
|
def setUp(self): |
|
|
|
self.project = prepare_project(task=DOCUMENT_CLASSIFICATION) |
|
|
|
self.non_member = make_user() |
|
|
|
doc = make_doc(self.project.item) |
|
|
|
self.url = reverse(viewname='approve_labels', args=[self.project.item.id, doc.id]) |
|
|
|
|
|
|
|
def test_allow_project_admin_and_approver_to_approve_and_disapprove(self): |
|
|
|
for member in self.project.users[:2]: |
|
|
|
self.data = {'approved': True} |
|
|
|
response = self.assert_create(member, status.HTTP_200_OK) |
|
|
|
self.assertEqual(response.data['annotation_approver'], member.username) |
|
|
|
self.data = {'approved': False} |
|
|
|
response = self.assert_create(member, status.HTTP_200_OK) |
|
|
|
self.assertIsNone(response.data['annotation_approver']) |
|
|
|
|
|
|
|
def test_denies_annotator_to_approve_and_disapprove(self): |
|
|
|
self.assert_create(self.project.users[2], status.HTTP_403_FORBIDDEN) |
|
|
@ -1,7 +1,7 @@ |
|
|
|
from django.urls import include, path |
|
|
|
|
|
|
|
from .views import (annotation, comment, example, example_state, health, label, |
|
|
|
project, tag, task) |
|
|
|
from .views import (comment, example, example_state, health, label, project, |
|
|
|
tag, task) |
|
|
|
from .views.tasks import category, relation, span, text |
|
|
|
|
|
|
|
urlpatterns_project = [ |
|
|
@ -75,11 +75,6 @@ urlpatterns_project = [ |
|
|
|
view=relation.RelationDetail.as_view(), |
|
|
|
name='annotation_relation_detail' |
|
|
|
), |
|
|
|
path( |
|
|
|
route='approval/<int:example_id>', |
|
|
|
view=annotation.ApprovalAPI.as_view(), |
|
|
|
name='approve_labels' |
|
|
|
), |
|
|
|
path( |
|
|
|
route='examples/<int:example_id>/categories', |
|
|
|
view=category.CategoryListAPI.as_view(), |
|
|
|
|
|
@ -1,20 +0,0 @@ |
|
|
|
from django.shortcuts import get_object_or_404 |
|
|
|
from rest_framework.permissions import IsAuthenticated |
|
|
|
from rest_framework.response import Response |
|
|
|
from rest_framework.views import APIView |
|
|
|
|
|
|
|
from members.permissions import IsAnnotationApprover, IsProjectAdmin |
|
|
|
|
|
|
|
from ..models import Example |
|
|
|
from ..serializers import ApproverSerializer |
|
|
|
|
|
|
|
|
|
|
|
class ApprovalAPI(APIView): |
|
|
|
permission_classes = [IsAuthenticated & (IsAnnotationApprover | IsProjectAdmin)] |
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
approved = self.request.data.get('approved', True) |
|
|
|
example = get_object_or_404(Example, pk=self.kwargs['example_id']) |
|
|
|
example.annotations_approved_by = self.request.user if approved else None |
|
|
|
example.save() |
|
|
|
return Response(ApproverSerializer(example).data) |
|
|
@ -15,7 +15,5 @@ export interface ExampleRepository { |
|
|
|
|
|
|
|
findById(projectId: string, exampleId: number): Promise<ExampleItem> |
|
|
|
|
|
|
|
approve(projectId: string, docId: number, approved: boolean): Promise<void> |
|
|
|
|
|
|
|
confirm(projectId: string, exampleId: number): Promise<void> |
|
|
|
} |
|
|
@ -42,11 +42,6 @@ export class APIExampleRepository implements ExampleRepository { |
|
|
|
return plainToInstance(ExampleItem, response.data) |
|
|
|
} |
|
|
|
|
|
|
|
async approve(projectId: string, exampleId: number, approved: boolean): Promise<void> { |
|
|
|
const url = `/projects/${projectId}/approval/${exampleId}` |
|
|
|
await this.request.post(url, { approved }) |
|
|
|
} |
|
|
|
|
|
|
|
async confirm(projectId: string, exampleId: number): Promise<void> { |
|
|
|
const url = `/projects/${projectId}/examples/${exampleId}/states` |
|
|
|
await this.request.post(url, {}) |
|
|
|
|
|
@ -57,10 +57,6 @@ export class ExampleApplicationService { |
|
|
|
return new ExampleDTO(response) |
|
|
|
} |
|
|
|
|
|
|
|
public async approve(projectId: string, docId: number, approved: boolean): Promise<void> { |
|
|
|
await this.repository.approve(projectId, docId, approved) |
|
|
|
} |
|
|
|
|
|
|
|
public async confirm(projectId: string, exampleId: number): Promise<void> { |
|
|
|
await this.repository.confirm(projectId, exampleId) |
|
|
|
} |
|
|
|