Skip to content

Commit

Permalink
Remove rest api for buld lead delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Rup-Narayan-Rajbanshi committed Sep 27, 2024
1 parent 52edd14 commit 5af11f6
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 72 deletions.
40 changes: 0 additions & 40 deletions apps/lead/tests/test_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,46 +131,6 @@ def test_lead_create_with_status_validated(self, assignee=None):
r_data = response.data
self.assertEqual(r_data['status'], data['status'])

def test_pre_bulk_delete_leads(self):
project = self.create(Project)
lead1 = self.create(Lead, project=project)
lead3 = self.create(Lead, project=project)

lead_ids = [lead1.id, lead3.id]
admin_user = self.create(User)
project.add_member(admin_user, role=self.admin_role)
url = '/api/v1/project/{}/leads/dry-bulk-delete/'.format(project.id)
self.authenticate(admin_user)
response = self.client.post(url, {'leads': lead_ids})
self.assert_200(response)
r_data = response.data
self.assertIn('entries', r_data)

def test_bulk_delete_leads(self):
project = self.create(Project)
lead1 = self.create(Lead, project=project)
self.create(Lead, project=project)
lead3 = self.create(Lead, project=project)
lead_count = Lead.objects.count()

lead_ids = [lead1.id, lead3.id]
url = '/api/v1/project/{}/leads/bulk-delete/'.format(project.id)

# calling without delete permissions
view_user = self.create(User)
project.add_member(view_user, role=self.view_only_role)
self.authenticate(view_user)
response = self.client.post(url, {'leads': lead_ids})
self.assert_403(response)

admin_user = self.create(User)
project.add_member(admin_user, role=self.admin_role)
self.authenticate(admin_user)
response = self.client.post(url, {'leads': lead_ids})
self.assert_204(response)

self.assertLess(Lead.objects.count(), lead_count)

def test_create_high_priority_lead(self, assignee=None):
lead_count = Lead.objects.count()
project = self.create(Project, role=self.admin_role)
Expand Down
30 changes: 1 addition & 29 deletions apps/lead/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import django_filters

from deep.permissions import ModifyPermission, CreateLeadPermission, DeleteLeadPermission
from deep.permissions import ModifyPermission, CreateLeadPermission
from deep.paginations import AutocompleteSetPagination
from deep.authentication import CSRFExemptSessionAuthentication

Expand Down Expand Up @@ -237,34 +237,6 @@ def leads_filter(self, request, version=None):
return response


class LeadBulkDeleteViewSet(viewsets.GenericViewSet):
permission_classes = [permissions.IsAuthenticated, DeleteLeadPermission]

def get_serializer_class(self):
# required by ViewSchema generator
return serializers.Serializer

@action(
detail=False,
methods=['post'],
url_path='dry-bulk-delete',
)
def dry_bulk_delete(self, request, project_id, version=None):
lead_ids = request.data.get('leads', [])
tbd_entities = Lead.get_associated_entities(project_id, lead_ids)
return response.Response(tbd_entities, status=status.HTTP_200_OK)

@action(
detail=False,
methods=['post'],
url_path='bulk-delete',
)
def bulk_delete(self, request, project_id, version=None):
lead_ids = request.data.get('leads', [])
Lead.objects.filter(project_id=project_id, id__in=lead_ids).delete()
return response.Response(status=status.HTTP_204_NO_CONTENT)


class LeadPreviewViewSet(viewsets.ReadOnlyModelViewSet):
serializer_class = LeadPreviewSerializer
permission_classes = [permissions.IsAuthenticated,
Expand Down
3 changes: 0 additions & 3 deletions deep/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
from lead.views import (
LeadGroupViewSet,
LeadViewSet,
LeadBulkDeleteViewSet,
LeadPreviewViewSet,
LeadOptionsView,
LeadExtractionTriggerView,
Expand Down Expand Up @@ -255,8 +254,6 @@
basename='lead_group')
router.register(r'leads', LeadViewSet,
basename='lead')
router.register(r'project/(?P<project_id>\d+)/leads', LeadBulkDeleteViewSet,
basename='leads-bulk')
router.register(r'lead-previews', LeadPreviewViewSet,
basename='lead_preview')

Expand Down

0 comments on commit 5af11f6

Please sign in to comment.