From 58d1d8f1327d1ce33c228f9bd001dd7a953586dd Mon Sep 17 00:00:00 2001 From: pablohashescobar <118773738+pablohashescobar@users.noreply.github.com> Date: Mon, 5 Jun 2023 12:51:30 +0530 Subject: [PATCH] fix: issue search for blocking and blocked_by condition (#1182) * fix: issue search for blocking and blocked_by condition * fix: issue search endpoint blockers * fix: rectify the filter parameters --- apiserver/plane/api/views/search.py | 13 ++++++++++--- apiserver/plane/utils/issue_search.py | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/apiserver/plane/api/views/search.py b/apiserver/plane/api/views/search.py index 823a1fcc8..88dddc43c 100644 --- a/apiserver/plane/api/views/search.py +++ b/apiserver/plane/api/views/search.py @@ -210,13 +210,15 @@ class IssueSearchEndpoint(BaseAPIView): blocker_blocked_by = request.query_params.get("blocker_blocked_by", False) issue_id = request.query_params.get("issue_id", False) - issues = search_issues(query) - issues = issues.filter( + issues = Issue.objects.filter( workspace__slug=slug, project_id=project_id, project__project_projectmember__member=self.request.user, ) + if query: + issues = search_issues(query, issues) + if parent == "true" and issue_id: issue = Issue.objects.get(pk=issue_id) issues = issues.filter( @@ -227,7 +229,12 @@ class IssueSearchEndpoint(BaseAPIView): ) ) if blocker_blocked_by == "true" and issue_id: - issues = issues.filter(blocker_issues=issue_id, blocked_issues=issue_id) + issue = Issue.objects.get(pk=issue_id) + issues = issues.filter( + ~Q(pk=issue_id), + ~Q(blocked_issues__block=issue), + ~Q(blocker_issues__blocked_by=issue), + ) return Response( issues.values( diff --git a/apiserver/plane/utils/issue_search.py b/apiserver/plane/utils/issue_search.py index 93b0df6da..40f85dde4 100644 --- a/apiserver/plane/utils/issue_search.py +++ b/apiserver/plane/utils/issue_search.py @@ -8,7 +8,7 @@ from django.db.models import Q from plane.db.models import Issue -def search_issues(query): +def search_issues(query, queryset): fields = ["name", "sequence_id"] q = Q() for field in fields: @@ -18,6 +18,6 @@ def search_issues(query): q |= Q(**{"sequence_id": sequence_id}) else: q |= Q(**{f"{field}__icontains": query}) - return Issue.objects.filter( + return queryset.filter( q, ).distinct()