Skip to content

Commit

Permalink
fix: issue ordering for priority and updated_by parameters (makeplane…
Browse files Browse the repository at this point in the history
  • Loading branch information
pablohashescobar authored May 26, 2023
1 parent b632143 commit f80b3f1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
4 changes: 4 additions & 0 deletions apiserver/plane/api/serializers/issue.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Django imports
from django.utils import timezone

# Third Party imports
from rest_framework import serializers

Expand Down Expand Up @@ -251,6 +254,7 @@ def update(self, instance, validated_data):
batch_size=10,
)

instance.updated_at = timezone.now()
return super().update(instance, validated_data)


Expand Down
42 changes: 38 additions & 4 deletions apiserver/plane/api/views/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@
from itertools import chain

# Django imports
from django.db.models import Prefetch, OuterRef, Func, F, Q, Count
from django.db.models import (
Prefetch,
OuterRef,
Func,
F,
Q,
Count,
Case,
Value,
CharField,
When,
)
from django.core.serializers.json import DjangoJSONEncoder
from django.utils.decorators import method_decorator
from django.views.decorators.gzip import gzip_page
from django.db.models.functions import Coalesce
from django.conf import settings

# Third Party imports
from rest_framework.response import Response
from rest_framework import status
Expand Down Expand Up @@ -144,9 +156,13 @@ def list(self, request, slug, project_id):
filters = issue_filters(request.query_params, "GET")
show_sub_issues = request.GET.get("show_sub_issues", "true")

# Custom ordering for priority
priority_order = ["urgent", "high", "medium", "low", None]

order_by_param = request.GET.get("order_by", "-created_at")

issue_queryset = (
self.get_queryset()
.order_by(request.GET.get("order_by", "created_at"))
.filter(**filters)
.annotate(cycle_id=F("issue_cycle__id"))
.annotate(module_id=F("issue_module__id"))
Expand All @@ -166,6 +182,19 @@ def list(self, request, slug, project_id):
)
)

if order_by_param == "priority":
issue_queryset = issue_queryset.annotate(
priority_order=Case(
*[
When(priority=p, then=Value(i))
for i, p in enumerate(priority_order)
],
output_field=CharField(),
)
).order_by("priority_order")
else:
issue_queryset = issue_queryset.order_by(order_by_param)

issue_queryset = (
issue_queryset
if show_sub_issues == "true"
Expand Down Expand Up @@ -789,8 +818,13 @@ def post(self, request, slug, project_id, issue_id):
if serializer.is_valid():
serializer.save(project_id=project_id, issue_id=issue_id)
response_data = serializer.data
if settings.DOCKERIZED and settings.AWS_S3_ENDPOINT_URL in response_data["asset"]:
response_data["asset"] = response_data["asset"].replace(settings.AWS_S3_ENDPOINT_URL, settings.WEB_URL)
if (
settings.DOCKERIZED
and settings.AWS_S3_ENDPOINT_URL in response_data["asset"]
):
response_data["asset"] = response_data["asset"].replace(
settings.AWS_S3_ENDPOINT_URL, settings.WEB_URL
)
issue_activity.delay(
type="attachment.activity.created",
requested_data=None,
Expand Down

0 comments on commit f80b3f1

Please sign in to comment.