* chore: removed inbox id * fix: inbox changes * chore: resolved merge conflicts * chore: inbox issue response changes * chore: inbox issue filters * fix: inbox implementation revamp * fix: type fixes * fix: pagination implementation * fix: inbox fixes * fix: pagination fixes * fix: inbox Issues pagination fixes * chore: triage state change * fix: inbox fixes * chore: filtering using boolean * chore: total results in the pagination * fix: inbox main content changes * fix: develop pull fixes * chore: resolved build erros in inbox issues * dev: fix migrations * chore: module, labels and assignee in inbox * chore: inbox issue order by * chore: inbox filters * chore: inbox ui revamp * chore: inbox type updated * chore: updated filters * chore: updated filter menmbers and date types in inbox issue filter * chore: inbox issue filter updated * chore: updated date filter in the inbox issue filter * chore: moved the current tab state from local state to store * chore: updated the filter and fetch request in the inbox issues * chore: updated tab change handler * chore: handled isEmpty in the issue filters query params * chore: inbox sidebar updated * chore: enabled create inbox issue in mobx * chore: replaced the key inbox_status to status * chore: inbox sidebar pagination * chore: updated inbox issue services * chore: inbox sidebar total count indicator * chore: create inbox issue updated * chore: updated inbox issue sidebar layout * chore: rendering issue detail in inbox issue * chore: inbox issue content updated * chore: create inbox issue modal description improvement * fix: updated delete functionality in inbox store * chore: updated multiple inbox issue creation * chore: handled loading, empty states and inbox user access permissions * chore: updated rendering issues in the sidebar * chore: inbox sidebar label improvement * chore: handled empty states * chore: disabled inbox empty state added * chore: module, labels and assignee in list endpoint * chore: labels in list endpoint * chore: inboc issue serializer * chore: representation in serializer * chore: super function * chore: inbox empty state updated * chore: implemented applied filters * chore: inbox empty state updated * chore: update date formats in applied filters * chore: inbox skeleton updated * chore: ui changes in the siebar list item * chore: removed the module and cycle ids * chore: inbox sidebar tab * chore: inbox actions * chore: updated inbox issue header actions * chore: updated inbox issue code cleanup * chore: loader improvement * chore: inbox sidebar improvement * chore: inbox sidebar empty state flicker * fix: inbox issue delete operation * chore: inbox issue title and description update indicator added * fix: resolved issue property rendering in initial load * chore: inbox sidebar and detail header improvement * fix: handling selected filter in the issue filters and applied filters * chore: inbox issue detail improvement * chore: inbox issue label updated * chore: inbox issue sidebar improvement * fix: handling issue description update when we move between the issues in inbox * chore: removed inbox issue helpers file * chore: boolean checked * chore: resolved file change requests --------- Co-authored-by: NarayanBavisetti <narayan3119@gmail.com> Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com> Co-authored-by: pablohashescobar <nikhilschacko@gmail.com> Co-authored-by: Anmol Singh Bhatia <anmolsinghbhatia@plane.so>
103 lines
3.6 KiB
Python
103 lines
3.6 KiB
Python
# Python imports
|
|
from itertools import groupby
|
|
|
|
# Django imports
|
|
from django.db.models import Q
|
|
|
|
# Third party imports
|
|
from rest_framework.response import Response
|
|
from rest_framework import status
|
|
|
|
# Module imports
|
|
from .. import BaseViewSet
|
|
from plane.app.serializers import StateSerializer
|
|
from plane.app.permissions import (
|
|
ProjectEntityPermission,
|
|
)
|
|
from plane.db.models import State, Issue
|
|
from plane.utils.cache import invalidate_cache
|
|
|
|
class StateViewSet(BaseViewSet):
|
|
serializer_class = StateSerializer
|
|
model = State
|
|
permission_classes = [
|
|
ProjectEntityPermission,
|
|
]
|
|
|
|
def get_queryset(self):
|
|
return self.filter_queryset(
|
|
super()
|
|
.get_queryset()
|
|
.filter(workspace__slug=self.kwargs.get("slug"))
|
|
.filter(project_id=self.kwargs.get("project_id"))
|
|
.filter(
|
|
project__project_projectmember__member=self.request.user,
|
|
project__project_projectmember__is_active=True,
|
|
project__archived_at__isnull=True,
|
|
)
|
|
.filter(is_triage=False)
|
|
.select_related("project")
|
|
.select_related("workspace")
|
|
.distinct()
|
|
)
|
|
|
|
@invalidate_cache(path="workspaces/:slug/states/", url_params=True, user=False)
|
|
def create(self, request, slug, project_id):
|
|
serializer = StateSerializer(data=request.data)
|
|
if serializer.is_valid():
|
|
serializer.save(project_id=project_id)
|
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
|
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
|
|
|
def list(self, request, slug, project_id):
|
|
states = StateSerializer(self.get_queryset(), many=True).data
|
|
grouped = request.GET.get("grouped", False)
|
|
if grouped == "true":
|
|
state_dict = {}
|
|
for key, value in groupby(
|
|
sorted(states, key=lambda state: state["group"]),
|
|
lambda state: state.get("group"),
|
|
):
|
|
state_dict[str(key)] = list(value)
|
|
return Response(state_dict, status=status.HTTP_200_OK)
|
|
return Response(states, status=status.HTTP_200_OK)
|
|
|
|
@invalidate_cache(path="workspaces/:slug/states/", url_params=True, user=False)
|
|
def mark_as_default(self, request, slug, project_id, pk):
|
|
# Select all the states which are marked as default
|
|
_ = State.objects.filter(
|
|
workspace__slug=slug, project_id=project_id, default=True
|
|
).update(default=False)
|
|
_ = State.objects.filter(
|
|
workspace__slug=slug, project_id=project_id, pk=pk
|
|
).update(default=True)
|
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
|
|
|
@invalidate_cache(path="workspaces/:slug/states/", url_params=True, user=False)
|
|
def destroy(self, request, slug, project_id, pk):
|
|
state = State.objects.get(
|
|
is_triage=False,
|
|
pk=pk,
|
|
project_id=project_id,
|
|
workspace__slug=slug,
|
|
)
|
|
|
|
if state.default:
|
|
return Response(
|
|
{"error": "Default state cannot be deleted"},
|
|
status=status.HTTP_400_BAD_REQUEST,
|
|
)
|
|
|
|
# Check for any issues in the state
|
|
issue_exist = Issue.issue_objects.filter(state=pk).exists()
|
|
|
|
if issue_exist:
|
|
return Response(
|
|
{
|
|
"error": "The state is not empty, only empty states can be deleted"
|
|
},
|
|
status=status.HTTP_400_BAD_REQUEST,
|
|
)
|
|
|
|
state.delete()
|
|
return Response(status=status.HTTP_204_NO_CONTENT)
|