mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
fix: model ordering (#521)
* fix: model ordering * fix: my pages and create by others pages
This commit is contained in:
parent
c6ba93da72
commit
5152deb2d0
@ -26,9 +26,6 @@ from plane.db.models import (
|
||||
CycleIssue,
|
||||
Issue,
|
||||
CycleFavorite,
|
||||
IssueBlocker,
|
||||
IssueLink,
|
||||
ModuleIssue,
|
||||
)
|
||||
from plane.bgtasks.issue_activites_task import issue_activity
|
||||
from plane.utils.grouper import group_results
|
||||
@ -95,6 +92,7 @@ class CycleViewSet(BaseViewSet):
|
||||
filter=Q(issue_cycle__issue__state__group="backlog"),
|
||||
)
|
||||
)
|
||||
.order_by("name", "-is_favorite")
|
||||
.distinct()
|
||||
)
|
||||
|
||||
@ -409,6 +407,7 @@ class CurrentUpcomingCyclesEndpoint(BaseAPIView):
|
||||
filter=Q(issue_cycle__issue__state__group="backlog"),
|
||||
)
|
||||
)
|
||||
.order_by("name", "-is_favorite")
|
||||
)
|
||||
|
||||
upcoming_cycle = (
|
||||
@ -452,6 +451,7 @@ class CurrentUpcomingCyclesEndpoint(BaseAPIView):
|
||||
filter=Q(issue_cycle__issue__state__group="backlog"),
|
||||
)
|
||||
)
|
||||
.order_by("name", "-is_favorite")
|
||||
)
|
||||
|
||||
return Response(
|
||||
@ -524,6 +524,7 @@ class CompletedCyclesEndpoint(BaseAPIView):
|
||||
filter=Q(issue_cycle__issue__state__group="backlog"),
|
||||
)
|
||||
)
|
||||
.order_by("name", "-is_favorite")
|
||||
)
|
||||
|
||||
return Response(
|
||||
@ -550,6 +551,12 @@ class DraftCyclesEndpoint(BaseAPIView):
|
||||
|
||||
def get(self, request, slug, project_id):
|
||||
try:
|
||||
subquery = CycleFavorite.objects.filter(
|
||||
user=self.request.user,
|
||||
cycle_id=OuterRef("pk"),
|
||||
project_id=project_id,
|
||||
workspace__slug=slug,
|
||||
)
|
||||
draft_cycles = (
|
||||
Cycle.objects.filter(
|
||||
workspace__slug=slug,
|
||||
@ -560,6 +567,7 @@ class DraftCyclesEndpoint(BaseAPIView):
|
||||
.select_related("project")
|
||||
.select_related("workspace")
|
||||
.select_related("owned_by")
|
||||
.annotate(is_favorite=Exists(subquery))
|
||||
.annotate(total_issues=Count("issue_cycle"))
|
||||
.annotate(
|
||||
completed_issues=Count(
|
||||
@ -591,6 +599,7 @@ class DraftCyclesEndpoint(BaseAPIView):
|
||||
filter=Q(issue_cycle__issue__state__group="backlog"),
|
||||
)
|
||||
)
|
||||
.order_by("name", "-is_favorite")
|
||||
)
|
||||
|
||||
return Response(
|
||||
|
@ -213,7 +213,9 @@ class ImportServiceEndpoint(BaseAPIView):
|
||||
|
||||
def get(self, request, slug):
|
||||
try:
|
||||
imports = Importer.objects.filter(workspace__slug=slug)
|
||||
imports = Importer.objects.filter(workspace__slug=slug).order_by(
|
||||
"-created_at"
|
||||
)
|
||||
serializer = ImporterSerializer(imports, many=True)
|
||||
return Response(serializer.data)
|
||||
except Exception as e:
|
||||
|
@ -293,6 +293,7 @@ class UserWorkSpaceIssues(BaseAPIView):
|
||||
).select_related("created_by"),
|
||||
)
|
||||
)
|
||||
.order_by("-created_at")
|
||||
)
|
||||
serializer = IssueSerializer(issues, many=True)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
@ -311,8 +312,10 @@ class WorkSpaceIssuesEndpoint(BaseAPIView):
|
||||
|
||||
def get(self, request, slug):
|
||||
try:
|
||||
issues = Issue.objects.filter(workspace__slug=slug).filter(
|
||||
project__project_projectmember__member=self.request.user
|
||||
issues = (
|
||||
Issue.objects.filter(workspace__slug=slug)
|
||||
.filter(project__project_projectmember__member=self.request.user)
|
||||
.order_by("-created_at")
|
||||
)
|
||||
serializer = IssueSerializer(issues, many=True)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
@ -338,7 +341,7 @@ class IssueActivityEndpoint(BaseAPIView):
|
||||
project__project_projectmember__member=self.request.user,
|
||||
)
|
||||
.select_related("actor")
|
||||
).order_by("created_by")
|
||||
).order_by("created_at")
|
||||
issue_comments = (
|
||||
IssueComment.objects.filter(issue_id=issue_id)
|
||||
.filter(project__project_projectmember__member=self.request.user)
|
||||
@ -565,6 +568,7 @@ class LabelViewSet(BaseViewSet):
|
||||
.select_related("project")
|
||||
.select_related("workspace")
|
||||
.select_related("parent")
|
||||
.order_by("name")
|
||||
.distinct()
|
||||
)
|
||||
|
||||
@ -719,6 +723,7 @@ class IssueLinkViewSet(BaseViewSet):
|
||||
.filter(project_id=self.kwargs.get("project_id"))
|
||||
.filter(issue_id=self.kwargs.get("issue_id"))
|
||||
.filter(project__project_projectmember__member=self.request.user)
|
||||
.order_by("-created_at")
|
||||
.distinct()
|
||||
)
|
||||
|
||||
|
@ -102,6 +102,7 @@ class ModuleViewSet(BaseViewSet):
|
||||
filter=Q(issue_module__issue__state__group="backlog"),
|
||||
)
|
||||
)
|
||||
.order_by("name", "-is_favorite")
|
||||
)
|
||||
|
||||
def create(self, request, slug, project_id):
|
||||
@ -337,6 +338,7 @@ class ModuleLinkViewSet(BaseViewSet):
|
||||
.filter(project_id=self.kwargs.get("project_id"))
|
||||
.filter(module_id=self.kwargs.get("module_id"))
|
||||
.filter(project__project_projectmember__member=self.request.user)
|
||||
.order_by("-created_at")
|
||||
.distinct()
|
||||
)
|
||||
|
||||
|
@ -60,6 +60,8 @@ class PageViewSet(BaseViewSet):
|
||||
.annotate(is_favorite=Exists(subquery))
|
||||
.order_by(self.request.GET.get("order_by", "-created_at"))
|
||||
.prefetch_related("labels")
|
||||
|
||||
.order_by("name", "-is_favorite")
|
||||
.prefetch_related(
|
||||
Prefetch(
|
||||
"blocks", queryset=PageBlock.objects.select_related("page", "issue")
|
||||
@ -112,6 +114,7 @@ class PageBlockViewSet(BaseViewSet):
|
||||
.select_related("workspace")
|
||||
.select_related("page")
|
||||
.select_related("issue")
|
||||
.order_by("sort_order")
|
||||
.distinct()
|
||||
)
|
||||
|
||||
@ -258,6 +261,7 @@ class RecentPagesEndpoint(BaseAPIView):
|
||||
.select_related("workspace")
|
||||
.select_related("owned_by")
|
||||
.prefetch_related("labels")
|
||||
.order_by("-updated_by")
|
||||
)
|
||||
|
||||
earlier_this_week = (
|
||||
@ -323,6 +327,7 @@ class FavoritePagesEndpoint(BaseAPIView):
|
||||
.select_related("workspace")
|
||||
.select_related("owned_by")
|
||||
.prefetch_related("labels")
|
||||
.order_by("name", "-is_favorite")
|
||||
)
|
||||
|
||||
serializer = PageSerializer(pages, many=True)
|
||||
@ -342,6 +347,12 @@ class MyPagesEndpoint(BaseAPIView):
|
||||
|
||||
def get(self, request, slug, project_id):
|
||||
try:
|
||||
subquery = PageFavorite.objects.filter(
|
||||
user=request.user,
|
||||
page_id=OuterRef("pk"),
|
||||
project_id=project_id,
|
||||
workspace__slug=slug,
|
||||
)
|
||||
pages = (
|
||||
Page.objects.filter(
|
||||
workspace__slug=slug, project_id=project_id, owned_by=request.user
|
||||
@ -350,6 +361,8 @@ class MyPagesEndpoint(BaseAPIView):
|
||||
.select_related("workspace")
|
||||
.select_related("owned_by")
|
||||
.prefetch_related("labels")
|
||||
.annotate(is_favorite=Exists(subquery))
|
||||
.order_by("name", "-is_favorite")
|
||||
)
|
||||
serializer = PageSerializer(pages, many=True)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
@ -368,6 +381,12 @@ class CreatedbyOtherPagesEndpoint(BaseAPIView):
|
||||
|
||||
def get(self, request, slug, project_id):
|
||||
try:
|
||||
subquery = PageFavorite.objects.filter(
|
||||
user=request.user,
|
||||
page_id=OuterRef("pk"),
|
||||
project_id=project_id,
|
||||
workspace__slug=slug,
|
||||
)
|
||||
pages = (
|
||||
Page.objects.filter(
|
||||
~Q(owned_by=request.user),
|
||||
@ -378,6 +397,8 @@ class CreatedbyOtherPagesEndpoint(BaseAPIView):
|
||||
.select_related("workspace")
|
||||
.select_related("owned_by")
|
||||
.prefetch_related("labels")
|
||||
.annotate(is_favorite=Exists(subquery))
|
||||
.order_by("name", "-is_favorite")
|
||||
)
|
||||
serializer = PageSerializer(pages, many=True)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
|
@ -91,7 +91,7 @@ class ProjectViewSet(BaseViewSet):
|
||||
projects = (
|
||||
self.get_queryset()
|
||||
.annotate(is_favorite=Exists(subquery))
|
||||
.order_by("-is_favorite")
|
||||
.order_by("name", "-is_favorite")
|
||||
)
|
||||
return Response(ProjectDetailSerializer(projects, many=True).data)
|
||||
except Exception as e:
|
||||
@ -101,7 +101,6 @@ class ProjectViewSet(BaseViewSet):
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
|
||||
|
||||
def create(self, request, slug):
|
||||
try:
|
||||
workspace = Workspace.objects.get(slug=slug)
|
||||
|
@ -53,6 +53,7 @@ class IssueViewViewSet(BaseViewSet):
|
||||
.select_related("project")
|
||||
.select_related("workspace")
|
||||
.annotate(is_favorite=Exists(subquery))
|
||||
.order_by("name", "-is_favorite")
|
||||
.distinct()
|
||||
)
|
||||
|
||||
|
@ -70,7 +70,9 @@ class WorkSpaceViewSet(BaseViewSet):
|
||||
lookup_field = "slug"
|
||||
|
||||
def get_queryset(self):
|
||||
return self.filter_queryset(super().get_queryset().select_related("owner"))
|
||||
return self.filter_queryset(
|
||||
super().get_queryset().select_related("owner")
|
||||
).order_by("name")
|
||||
|
||||
def create(self, request):
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user