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
This commit is contained in:
pablohashescobar 2023-06-05 12:51:30 +05:30 committed by GitHub
parent 50060a0bf9
commit 58d1d8f132
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View File

@ -210,13 +210,15 @@ class IssueSearchEndpoint(BaseAPIView):
blocker_blocked_by = request.query_params.get("blocker_blocked_by", False) blocker_blocked_by = request.query_params.get("blocker_blocked_by", False)
issue_id = request.query_params.get("issue_id", False) issue_id = request.query_params.get("issue_id", False)
issues = search_issues(query) issues = Issue.objects.filter(
issues = issues.filter(
workspace__slug=slug, workspace__slug=slug,
project_id=project_id, project_id=project_id,
project__project_projectmember__member=self.request.user, project__project_projectmember__member=self.request.user,
) )
if query:
issues = search_issues(query, issues)
if parent == "true" and issue_id: if parent == "true" and issue_id:
issue = Issue.objects.get(pk=issue_id) issue = Issue.objects.get(pk=issue_id)
issues = issues.filter( issues = issues.filter(
@ -227,7 +229,12 @@ class IssueSearchEndpoint(BaseAPIView):
) )
) )
if blocker_blocked_by == "true" and issue_id: 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( return Response(
issues.values( issues.values(

View File

@ -8,7 +8,7 @@ from django.db.models import Q
from plane.db.models import Issue from plane.db.models import Issue
def search_issues(query): def search_issues(query, queryset):
fields = ["name", "sequence_id"] fields = ["name", "sequence_id"]
q = Q() q = Q()
for field in fields: for field in fields:
@ -18,6 +18,6 @@ def search_issues(query):
q |= Q(**{"sequence_id": sequence_id}) q |= Q(**{"sequence_id": sequence_id})
else: else:
q |= Q(**{f"{field}__icontains": query}) q |= Q(**{f"{field}__icontains": query})
return Issue.objects.filter( return queryset.filter(
q, q,
).distinct() ).distinct()