From e17396b8d47a723a2cc5dd988a5b644582cb0c13 Mon Sep 17 00:00:00 2001 From: NarayanBavisetti Date: Fri, 14 Jun 2024 13:43:01 +0530 Subject: [PATCH] chore: removed bulk operations --- apiserver/plane/app/urls/issue.py | 12 - apiserver/plane/app/views/__init__.py | 5 +- apiserver/plane/app/views/issue/base.py | 1 + .../plane/app/views/issue/bulk_operations.py | 288 ------------------ 4 files changed, 2 insertions(+), 304 deletions(-) delete mode 100644 apiserver/plane/app/views/issue/bulk_operations.py diff --git a/apiserver/plane/app/urls/issue.py b/apiserver/plane/app/urls/issue.py index 9b7a1841a..cc0109b1a 100644 --- a/apiserver/plane/app/urls/issue.py +++ b/apiserver/plane/app/urls/issue.py @@ -20,8 +20,6 @@ from plane.app.views import ( IssueViewSet, LabelViewSet, IssueDescriptionViewSet, - BulkIssueOperationsEndpoint, - BulkArchiveIssuesEndpoint, ArchivedIssueDescriptionViewSet, ) @@ -95,11 +93,6 @@ urlpatterns = [ BulkDeleteIssuesEndpoint.as_view(), name="project-issues-bulk", ), - path( - "workspaces//projects//bulk-archive-issues/", - BulkArchiveIssuesEndpoint.as_view(), - name="bulk-archive-issues", - ), ## path( "workspaces//projects//issues//sub-issues/", @@ -327,11 +320,6 @@ urlpatterns = [ ), name="project-issue-draft", ), - path( - "workspaces//projects//bulk-operation-issues/", - BulkIssueOperationsEndpoint.as_view(), - name="bulk-operations-issues", - ), path( "workspaces//projects//issue-drafts//description/", IssueDraftViewSet.as_view( diff --git a/apiserver/plane/app/views/__init__.py b/apiserver/plane/app/views/__init__.py index 8a7561beb..52c372424 100644 --- a/apiserver/plane/app/views/__init__.py +++ b/apiserver/plane/app/views/__init__.py @@ -114,7 +114,7 @@ from .issue.activity import ( IssueActivityEndpoint, ) -from .issue.archive import IssueArchiveViewSet, BulkArchiveIssuesEndpoint +from .issue.archive import IssueArchiveViewSet from .issue.archive import IssueArchiveViewSet, ArchivedIssueDescriptionViewSet from .issue.attachment import ( @@ -153,9 +153,6 @@ from .issue.subscriber import ( IssueSubscriberViewSet, ) - -from .issue.bulk_operations import BulkIssueOperationsEndpoint - from .module.base import ( ModuleViewSet, ModuleLinkViewSet, diff --git a/apiserver/plane/app/views/issue/base.py b/apiserver/plane/app/views/issue/base.py index 9ab285cd0..6a5baf355 100644 --- a/apiserver/plane/app/views/issue/base.py +++ b/apiserver/plane/app/views/issue/base.py @@ -5,6 +5,7 @@ import base64 # Django imports from django.contrib.postgres.aggregates import ArrayAgg from django.contrib.postgres.fields import ArrayField +from django.http import StreamingHttpResponse from django.core.serializers.json import DjangoJSONEncoder from django.db.models import ( Exists, diff --git a/apiserver/plane/app/views/issue/bulk_operations.py b/apiserver/plane/app/views/issue/bulk_operations.py deleted file mode 100644 index ea6637826..000000000 --- a/apiserver/plane/app/views/issue/bulk_operations.py +++ /dev/null @@ -1,288 +0,0 @@ -# Python imports -import json -from datetime import datetime - -# Django imports -from django.utils import timezone - -# Third Party imports -from rest_framework.response import Response -from rest_framework import status - -# Module imports -from .. import BaseAPIView -from plane.app.permissions import ( - ProjectEntityPermission, -) -from plane.db.models import ( - Project, - Issue, - IssueLabel, - IssueAssignee, -) -from plane.bgtasks.issue_activites_task import issue_activity - - -class BulkIssueOperationsEndpoint(BaseAPIView): - permission_classes = [ - ProjectEntityPermission, - ] - - def post(self, request, slug, project_id): - issue_ids = request.data.get("issue_ids", []) - if not len(issue_ids): - return Response( - {"error": "Issue IDs are required"}, - status=status.HTTP_400_BAD_REQUEST, - ) - - # Get all the issues - issues = ( - Issue.objects.filter( - workspace__slug=slug, project_id=project_id, pk__in=issue_ids - ) - .select_related("state") - .prefetch_related("labels", "assignees") - ) - # Current epoch - epoch = int(timezone.now().timestamp()) - - # Project details - project = Project.objects.get(workspace__slug=slug, pk=project_id) - workspace_id = project.workspace_id - - # Initialize arrays - bulk_update_issues = [] - bulk_issue_activities = [] - bulk_update_issue_labels = [] - bulk_update_issue_assignees = [] - - properties = request.data.get("properties", {}) - - if properties.get("start_date", False) and properties.get("target_date", False): - if ( - datetime.strptime(properties.get("start_date"), "%Y-%m-%d").date() - > datetime.strptime(properties.get("target_date"), "%Y-%m-%d").date() - ): - return Response( - { - "error_code": 4100, - "error_message": "INVALID_ISSUE_DATES", - }, - status=status.HTTP_400_BAD_REQUEST, - ) - - for issue in issues: - - # Priority - if properties.get("priority", False): - bulk_issue_activities.append( - { - "type": "issue.activity.updated", - "requested_data": json.dumps( - {"priority": properties.get("priority")} - ), - "current_instance": json.dumps( - {"priority": (issue.priority)} - ), - "issue_id": str(issue.id), - "actor_id": str(request.user.id), - "project_id": str(project_id), - "epoch": epoch, - } - ) - issue.priority = properties.get("priority") - - # State - if properties.get("state_id", False): - bulk_issue_activities.append( - { - "type": "issue.activity.updated", - "requested_data": json.dumps( - {"state": properties.get("state")} - ), - "current_instance": json.dumps( - {"state": str(issue.state_id)} - ), - "issue_id": str(issue.id), - "actor_id": str(request.user.id), - "project_id": str(project_id), - "epoch": epoch, - } - ) - issue.state_id = properties.get("state_id") - - # Start date - if properties.get("start_date", False): - if ( - issue.target_date - and not properties.get("target_date", False) - and issue.target_date - <= datetime.strptime( - properties.get("start_date"), "%Y-%m-%d" - ).date() - ): - return Response( - { - "error_code": 4101, - "error_message": "INVALID_ISSUE_START_DATE", - }, - status=status.HTTP_400_BAD_REQUEST, - ) - bulk_issue_activities.append( - { - "type": "issue.activity.updated", - "requested_data": json.dumps( - {"start_date": properties.get("start_date")} - ), - "current_instance": json.dumps( - {"start_date": str(issue.start_date)} - ), - "issue_id": str(issue.id), - "actor_id": str(request.user.id), - "project_id": str(project_id), - "epoch": epoch, - } - ) - issue.start_date = properties.get("start_date") - - # Target date - if properties.get("target_date", False): - if ( - issue.start_date - and not properties.get("start_date", False) - and issue.start_date - >= datetime.strptime( - properties.get("target_date"), "%Y-%m-%d" - ).date() - ): - return Response( - { - "error_code": 4102, - "error_message": "INVALID_ISSUE_TARGET_DATE", - }, - status=status.HTTP_400_BAD_REQUEST, - ) - bulk_issue_activities.append( - { - "type": "issue.activity.updated", - "requested_data": json.dumps( - {"target_date": properties.get("target_date")} - ), - "current_instance": json.dumps( - {"target_date": str(issue.target_date)} - ), - "issue_id": str(issue.id), - "actor_id": str(request.user.id), - "project_id": str(project_id), - "epoch": epoch, - } - ) - issue.target_date = properties.get("target_date") - - bulk_update_issues.append(issue) - - # Labels - if properties.get("label_ids", []): - for label_id in properties.get("label_ids", []): - bulk_update_issue_labels.append( - IssueLabel( - issue=issue, - label_id=label_id, - created_by=request.user, - project_id=project_id, - workspace_id=workspace_id, - ) - ) - bulk_issue_activities.append( - { - "type": "issue.activity.updated", - "requested_data": json.dumps( - {"label_ids": properties.get("label_ids", [])} - ), - "current_instance": json.dumps( - { - "label_ids": [ - str(label.id) - for label in issue.labels.all() - ] - } - ), - "issue_id": str(issue.id), - "actor_id": str(request.user.id), - "project_id": str(project_id), - "epoch": epoch, - } - ) - - # Assignees - if properties.get("assignee_ids", []): - for assignee_id in properties.get( - "assignee_ids", issue.assignees - ): - bulk_update_issue_assignees.append( - IssueAssignee( - issue=issue, - assignee_id=assignee_id, - created_by=request.user, - project_id=project_id, - workspace_id=workspace_id, - ) - ) - bulk_issue_activities.append( - { - "type": "issue.activity.updated", - "requested_data": json.dumps( - { - "assignee_ids": properties.get( - "assignee_ids", [] - ) - } - ), - "current_instance": json.dumps( - { - "assignee_ids": [ - str(assignee.id) - for assignee in issue.assignees.all() - ] - } - ), - "issue_id": str(issue.id), - "actor_id": str(request.user.id), - "project_id": str(project_id), - "epoch": epoch, - } - ) - - # Bulk update all the objects - Issue.objects.bulk_update( - bulk_update_issues, - [ - "priority", - "start_date", - "target_date", - "state", - ], - batch_size=100, - ) - - # Create new labels - IssueLabel.objects.bulk_create( - bulk_update_issue_labels, - ignore_conflicts=True, - batch_size=100, - ) - - # Create new assignees - IssueAssignee.objects.bulk_create( - bulk_update_issue_assignees, - ignore_conflicts=True, - batch_size=100, - ) - # update the issue activity - [ - issue_activity.delay(**activity) - for activity in bulk_issue_activities - ] - - return Response(status=status.HTTP_204_NO_CONTENT)