mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
chore: global search endpoint for workspace (#1649)
* chore: global search endpoint * chore: global search endpoitnt for workspace search
This commit is contained in:
parent
6db1db55e9
commit
afce027bf3
@ -20,7 +20,7 @@ class GlobalSearchEndpoint(BaseAPIView):
|
|||||||
also show related workspace if found
|
also show related workspace if found
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def filter_workspaces(self, query, slug, project_id):
|
def filter_workspaces(self, query, slug, project_id, workspace_search):
|
||||||
fields = ["name"]
|
fields = ["name"]
|
||||||
q = Q()
|
q = Q()
|
||||||
for field in fields:
|
for field in fields:
|
||||||
@ -31,8 +31,8 @@ class GlobalSearchEndpoint(BaseAPIView):
|
|||||||
.values("name", "id", "slug")
|
.values("name", "id", "slug")
|
||||||
)
|
)
|
||||||
|
|
||||||
def filter_projects(self, query, slug, project_id):
|
def filter_projects(self, query, slug, project_id, workspace_search):
|
||||||
fields = ["name"]
|
fields = ["name", "identifier"]
|
||||||
q = Q()
|
q = Q()
|
||||||
for field in fields:
|
for field in fields:
|
||||||
q |= Q(**{f"{field}__icontains": query})
|
q |= Q(**{f"{field}__icontains": query})
|
||||||
@ -46,8 +46,8 @@ class GlobalSearchEndpoint(BaseAPIView):
|
|||||||
.values("name", "id", "identifier", "workspace__slug")
|
.values("name", "id", "identifier", "workspace__slug")
|
||||||
)
|
)
|
||||||
|
|
||||||
def filter_issues(self, query, slug, project_id):
|
def filter_issues(self, query, slug, project_id, workspace_search):
|
||||||
fields = ["name", "sequence_id"]
|
fields = ["name", "sequence_id", "project__identifier"]
|
||||||
q = Q()
|
q = Q()
|
||||||
for field in fields:
|
for field in fields:
|
||||||
if field == "sequence_id":
|
if field == "sequence_id":
|
||||||
@ -56,111 +56,118 @@ class GlobalSearchEndpoint(BaseAPIView):
|
|||||||
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.issue_objects.filter(
|
issues = Issue.issue_objects.filter(
|
||||||
q,
|
q,
|
||||||
project__project_projectmember__member=self.request.user,
|
project__project_projectmember__member=self.request.user,
|
||||||
workspace__slug=slug,
|
workspace__slug=slug,
|
||||||
project_id=project_id,
|
|
||||||
)
|
|
||||||
.distinct()
|
|
||||||
.values(
|
|
||||||
"name",
|
|
||||||
"id",
|
|
||||||
"sequence_id",
|
|
||||||
"project__identifier",
|
|
||||||
"project_id",
|
|
||||||
"workspace__slug",
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def filter_cycles(self, query, slug, project_id):
|
if workspace_search == "false":
|
||||||
|
issues = issues.filter(project_id=project_id)
|
||||||
|
|
||||||
|
return issues.distinct().values(
|
||||||
|
"name",
|
||||||
|
"id",
|
||||||
|
"sequence_id",
|
||||||
|
"project__identifier",
|
||||||
|
"project_id",
|
||||||
|
"workspace__slug",
|
||||||
|
)
|
||||||
|
|
||||||
|
def filter_cycles(self, query, slug, project_id, workspace_search):
|
||||||
fields = ["name"]
|
fields = ["name"]
|
||||||
q = Q()
|
q = Q()
|
||||||
for field in fields:
|
for field in fields:
|
||||||
q |= Q(**{f"{field}__icontains": query})
|
q |= Q(**{f"{field}__icontains": query})
|
||||||
return (
|
|
||||||
Cycle.objects.filter(
|
cycles = Cycle.objects.filter(
|
||||||
q,
|
q,
|
||||||
project__project_projectmember__member=self.request.user,
|
project__project_projectmember__member=self.request.user,
|
||||||
workspace__slug=slug,
|
workspace__slug=slug,
|
||||||
project_id=project_id,
|
|
||||||
)
|
|
||||||
.distinct()
|
|
||||||
.values(
|
|
||||||
"name",
|
|
||||||
"id",
|
|
||||||
"project_id",
|
|
||||||
"workspace__slug",
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def filter_modules(self, query, slug, project_id):
|
if workspace_search == "false":
|
||||||
|
cycles = cycles.filter(project_id=project_id)
|
||||||
|
|
||||||
|
return cycles.distinct().values(
|
||||||
|
"name",
|
||||||
|
"id",
|
||||||
|
"project_id",
|
||||||
|
"workspace__slug",
|
||||||
|
)
|
||||||
|
|
||||||
|
def filter_modules(self, query, slug, project_id, workspace_search):
|
||||||
fields = ["name"]
|
fields = ["name"]
|
||||||
q = Q()
|
q = Q()
|
||||||
for field in fields:
|
for field in fields:
|
||||||
q |= Q(**{f"{field}__icontains": query})
|
q |= Q(**{f"{field}__icontains": query})
|
||||||
return (
|
|
||||||
Module.objects.filter(
|
modules = Module.objects.filter(
|
||||||
q,
|
q,
|
||||||
project__project_projectmember__member=self.request.user,
|
project__project_projectmember__member=self.request.user,
|
||||||
workspace__slug=slug,
|
workspace__slug=slug,
|
||||||
project_id=project_id,
|
|
||||||
)
|
|
||||||
.distinct()
|
|
||||||
.values(
|
|
||||||
"name",
|
|
||||||
"id",
|
|
||||||
"project_id",
|
|
||||||
"workspace__slug",
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def filter_pages(self, query, slug, project_id):
|
if workspace_search == "false":
|
||||||
|
modules = modules.filter(project_id=project_id)
|
||||||
|
|
||||||
|
return modules.distinct().values(
|
||||||
|
"name",
|
||||||
|
"id",
|
||||||
|
"project_id",
|
||||||
|
"workspace__slug",
|
||||||
|
)
|
||||||
|
|
||||||
|
def filter_pages(self, query, slug, project_id, workspace_search):
|
||||||
fields = ["name"]
|
fields = ["name"]
|
||||||
q = Q()
|
q = Q()
|
||||||
for field in fields:
|
for field in fields:
|
||||||
q |= Q(**{f"{field}__icontains": query})
|
q |= Q(**{f"{field}__icontains": query})
|
||||||
return (
|
|
||||||
Page.objects.filter(
|
pages = Page.objects.filter(
|
||||||
q,
|
q,
|
||||||
project__project_projectmember__member=self.request.user,
|
project__project_projectmember__member=self.request.user,
|
||||||
workspace__slug=slug,
|
workspace__slug=slug,
|
||||||
project_id=project_id,
|
|
||||||
)
|
|
||||||
.distinct()
|
|
||||||
.values(
|
|
||||||
"name",
|
|
||||||
"id",
|
|
||||||
"project_id",
|
|
||||||
"workspace__slug",
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def filter_views(self, query, slug, project_id):
|
if workspace_search == "false":
|
||||||
|
pages = pages.filter(project_id=project_id)
|
||||||
|
|
||||||
|
return pages.distinct().values(
|
||||||
|
"name",
|
||||||
|
"id",
|
||||||
|
"project_id",
|
||||||
|
"workspace__slug",
|
||||||
|
)
|
||||||
|
|
||||||
|
def filter_views(self, query, slug, project_id, workspace_search):
|
||||||
fields = ["name"]
|
fields = ["name"]
|
||||||
q = Q()
|
q = Q()
|
||||||
for field in fields:
|
for field in fields:
|
||||||
q |= Q(**{f"{field}__icontains": query})
|
q |= Q(**{f"{field}__icontains": query})
|
||||||
return (
|
|
||||||
IssueView.objects.filter(
|
issue_views = IssueView.objects.filter(
|
||||||
q,
|
q,
|
||||||
project__project_projectmember__member=self.request.user,
|
project__project_projectmember__member=self.request.user,
|
||||||
workspace__slug=slug,
|
workspace__slug=slug,
|
||||||
project_id=project_id,
|
)
|
||||||
)
|
|
||||||
.distinct()
|
if workspace_search == "false":
|
||||||
.values(
|
issue_views = issue_views.filter(project_id=project_id)
|
||||||
"name",
|
|
||||||
"id",
|
return issue_views.distinct().values(
|
||||||
"project_id",
|
"name",
|
||||||
"workspace__slug",
|
"id",
|
||||||
)
|
"project_id",
|
||||||
|
"workspace__slug",
|
||||||
)
|
)
|
||||||
|
|
||||||
def get(self, request, slug, project_id):
|
def get(self, request, slug, project_id):
|
||||||
try:
|
try:
|
||||||
query = request.query_params.get("search", False)
|
query = request.query_params.get("search", False)
|
||||||
|
workspace_search = request.query_params.get("workspace_search", "false")
|
||||||
|
|
||||||
if not query:
|
if not query:
|
||||||
return Response(
|
return Response(
|
||||||
{
|
{
|
||||||
@ -191,7 +198,7 @@ class GlobalSearchEndpoint(BaseAPIView):
|
|||||||
|
|
||||||
for model in MODELS_MAPPER.keys():
|
for model in MODELS_MAPPER.keys():
|
||||||
func = MODELS_MAPPER.get(model, None)
|
func = MODELS_MAPPER.get(model, None)
|
||||||
results[model] = func(query, slug, project_id)
|
results[model] = func(query, slug, project_id, workspace_search)
|
||||||
return Response({"results": results}, status=status.HTTP_200_OK)
|
return Response({"results": results}, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -254,7 +261,6 @@ class IssueSearchEndpoint(BaseAPIView):
|
|||||||
if module == "true":
|
if module == "true":
|
||||||
issues = issues.exclude(issue_module__isnull=False)
|
issues = issues.exclude(issue_module__isnull=False)
|
||||||
|
|
||||||
|
|
||||||
return Response(
|
return Response(
|
||||||
issues.values(
|
issues.values(
|
||||||
"name",
|
"name",
|
||||||
|
Loading…
Reference in New Issue
Block a user