diff --git a/apiserver/plane/api/urls.py b/apiserver/plane/api/urls.py index 90455bf21..6a1c07c17 100644 --- a/apiserver/plane/api/urls.py +++ b/apiserver/plane/api/urls.py @@ -1152,7 +1152,7 @@ urlpatterns = [ ## End Importer # Search path( - "workspaces//search/", + "workspaces//projects//search/", GlobalSearchEndpoint.as_view(), name="global-search", ), diff --git a/apiserver/plane/api/views/search.py b/apiserver/plane/api/views/search.py index 39a59a488..16652d762 100644 --- a/apiserver/plane/api/views/search.py +++ b/apiserver/plane/api/views/search.py @@ -1,3 +1,6 @@ +# Python imports +import re + # Django imports from django.db.models import Q @@ -16,7 +19,7 @@ class GlobalSearchEndpoint(BaseAPIView): also show related workspace if found """ - def filter_workspaces(self, query, slug): + def filter_workspaces(self, query, slug, project_id): fields = ["name"] q = Q() for field in fields: @@ -25,7 +28,7 @@ class GlobalSearchEndpoint(BaseAPIView): q, workspace_member__member=self.request.user ).values("name", "id", "slug") - def filter_projects(self, query, slug): + def filter_projects(self, query, slug, project_id): fields = ["name"] q = Q() for field in fields: @@ -36,15 +39,21 @@ class GlobalSearchEndpoint(BaseAPIView): workspace__slug=slug, ).values("name", "id", "identifier", "workspace__slug") - def filter_issues(self, query, slug): - fields = ["name"] + def filter_issues(self, query, slug, project_id): + fields = ["name", "sequence_id"] q = Q() for field in fields: - q |= Q(**{f"{field}__icontains": query}) + if field == "sequence_id": + sequences = re.findall(r"\d+\.\d+|\d+", query) + for sequence_id in sequences: + q |= Q(**{"sequence_id": sequence_id}) + else: + q |= Q(**{f"{field}__icontains": query}) return Issue.objects.filter( q, project__project_projectmember__member=self.request.user, workspace__slug=slug, + project_id=project_id, ).values( "name", "id", @@ -54,7 +63,7 @@ class GlobalSearchEndpoint(BaseAPIView): "workspace__slug", ) - def filter_cycles(self, query, slug): + def filter_cycles(self, query, slug, project_id): fields = ["name"] q = Q() for field in fields: @@ -63,6 +72,7 @@ class GlobalSearchEndpoint(BaseAPIView): q, project__project_projectmember__member=self.request.user, workspace__slug=slug, + project_id=project_id, ).values( "name", "id", @@ -70,7 +80,7 @@ class GlobalSearchEndpoint(BaseAPIView): "workspace__slug", ) - def filter_modules(self, query, slug): + def filter_modules(self, query, slug, project_id): fields = ["name"] q = Q() for field in fields: @@ -79,6 +89,7 @@ class GlobalSearchEndpoint(BaseAPIView): q, project__project_projectmember__member=self.request.user, workspace__slug=slug, + project_id=project_id, ).values( "name", "id", @@ -86,7 +97,7 @@ class GlobalSearchEndpoint(BaseAPIView): "workspace__slug", ) - def filter_pages(self, query, slug): + def filter_pages(self, query, slug, project_id): fields = ["name"] q = Q() for field in fields: @@ -95,6 +106,7 @@ class GlobalSearchEndpoint(BaseAPIView): q, project__project_projectmember__member=self.request.user, workspace__slug=slug, + project_id=project_id, ).values( "name", "id", @@ -102,7 +114,7 @@ class GlobalSearchEndpoint(BaseAPIView): "workspace__slug", ) - def filter_views(self, query, slug): + def filter_views(self, query, slug, project_id): fields = ["name"] q = Q() for field in fields: @@ -111,6 +123,7 @@ class GlobalSearchEndpoint(BaseAPIView): q, project__project_projectmember__member=self.request.user, workspace__slug=slug, + project_id=project_id, ).values( "name", "id", @@ -118,7 +131,7 @@ class GlobalSearchEndpoint(BaseAPIView): "workspace__slug", ) - def get(self, request, slug): + def get(self, request, slug, project_id): try: query = request.query_params.get("search", False) if not query: @@ -151,11 +164,11 @@ class GlobalSearchEndpoint(BaseAPIView): for model in MODELS_MAPPER.keys(): func = MODELS_MAPPER.get(model, None) - results[model] = func(query, slug) + results[model] = func(query, slug, project_id) return Response({"results": results}, status=status.HTTP_200_OK) except Exception as e: - capture_exception(e) + print(e) return Response( {"error": "Something went wrong please try again later"}, status=status.HTTP_400_BAD_REQUEST,