mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
refactor: remove bulk assign endpoint, merge it into a single create endpoint and update the create endpoint to maintain db integrity
This commit is contained in:
parent
87d9de8555
commit
0b94172ef7
@ -52,7 +52,6 @@ from plane.api.views import (
|
|||||||
AddMemberToProjectEndpoint,
|
AddMemberToProjectEndpoint,
|
||||||
ProjectJoinEndpoint,
|
ProjectJoinEndpoint,
|
||||||
BulkDeleteIssuesEndpoint,
|
BulkDeleteIssuesEndpoint,
|
||||||
BulkAssignIssuesToCycleEndpoint,
|
|
||||||
ProjectUserViewsEndpoint,
|
ProjectUserViewsEndpoint,
|
||||||
ModuleViewSet,
|
ModuleViewSet,
|
||||||
ModuleIssueViewSet,
|
ModuleIssueViewSet,
|
||||||
@ -444,11 +443,6 @@ urlpatterns = [
|
|||||||
),
|
),
|
||||||
name="project-cycle",
|
name="project-cycle",
|
||||||
),
|
),
|
||||||
path(
|
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/cycles/<uuid:cycle_id>/bulk-assign-issues/",
|
|
||||||
BulkAssignIssuesToCycleEndpoint.as_view(),
|
|
||||||
name="bulk-assign-cycle-issues",
|
|
||||||
),
|
|
||||||
## End Cycles
|
## End Cycles
|
||||||
# Issue
|
# Issue
|
||||||
path(
|
path(
|
||||||
|
@ -38,7 +38,7 @@ from .workspace import (
|
|||||||
from .state import StateViewSet
|
from .state import StateViewSet
|
||||||
from .shortcut import ShortCutViewSet
|
from .shortcut import ShortCutViewSet
|
||||||
from .view import ViewViewSet
|
from .view import ViewViewSet
|
||||||
from .cycle import CycleViewSet, CycleIssueViewSet, BulkAssignIssuesToCycleEndpoint
|
from .cycle import CycleViewSet, CycleIssueViewSet
|
||||||
from .asset import FileAssetEndpoint
|
from .asset import FileAssetEndpoint
|
||||||
from .issue import (
|
from .issue import (
|
||||||
IssueViewSet,
|
IssueViewSet,
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
# Third party imports
|
# Third party imports
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
|
from sentry_sdk import capture_exception
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from . import BaseViewSet, BaseAPIView
|
from . import BaseViewSet
|
||||||
from plane.api.serializers import CycleSerializer, CycleIssueSerializer
|
from plane.api.serializers import CycleSerializer, CycleIssueSerializer
|
||||||
from plane.api.permissions import ProjectEntityPermission
|
from plane.api.permissions import ProjectEntityPermission
|
||||||
from plane.db.models import Cycle, CycleIssue, Issue
|
from plane.db.models import Cycle, CycleIssue, Issue
|
||||||
@ -66,26 +67,27 @@ class CycleIssueViewSet(BaseViewSet):
|
|||||||
.distinct()
|
.distinct()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def create(self, request, slug, project_id, cycle_id):
|
||||||
class BulkAssignIssuesToCycleEndpoint(BaseAPIView):
|
|
||||||
|
|
||||||
permission_classes = [
|
|
||||||
ProjectEntityPermission,
|
|
||||||
]
|
|
||||||
|
|
||||||
def post(self, request, slug, project_id, cycle_id):
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
issue_ids = request.data.get("issue_ids")
|
issues = request.data.get("issue", [])
|
||||||
|
|
||||||
|
if not len(issues):
|
||||||
|
return Response(
|
||||||
|
{"error": "Issues are required"}, status=status.HTTP_400_BAD_REQUEST
|
||||||
|
)
|
||||||
|
|
||||||
cycle = Cycle.objects.get(
|
cycle = Cycle.objects.get(
|
||||||
workspace__slug=slug, project_id=project_id, pk=cycle_id
|
workspace__slug=slug, project_id=project_id, pk=cycle_id
|
||||||
)
|
)
|
||||||
|
|
||||||
issues = Issue.objects.filter(
|
issues = Issue.objects.filter(
|
||||||
pk__in=issue_ids, workspace__slug=slug, project_id=project_id
|
pk__in=issues, workspace__slug=slug, project_id=project_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Delete old records in order to maintain the database integrity
|
||||||
|
CycleIssue.objects.filter(issue_id__in=issues).delete()
|
||||||
|
|
||||||
CycleIssue.objects.bulk_create(
|
CycleIssue.objects.bulk_create(
|
||||||
[
|
[
|
||||||
CycleIssue(
|
CycleIssue(
|
||||||
@ -107,3 +109,9 @@ class BulkAssignIssuesToCycleEndpoint(BaseAPIView):
|
|||||||
return Response(
|
return Response(
|
||||||
{"error": "Cycle not found"}, status=status.HTTP_404_NOT_FOUND
|
{"error": "Cycle not found"}, status=status.HTTP_404_NOT_FOUND
|
||||||
)
|
)
|
||||||
|
except Exception as e:
|
||||||
|
capture_exception(e)
|
||||||
|
return Response(
|
||||||
|
{"error": "Something went wrong please try again later"},
|
||||||
|
status=status.HTTP_200_OK,
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user