Skip to content

Commit

Permalink
fix: build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
aaryan610 committed Dec 10, 2024
1 parent 16902fd commit 760d415
Show file tree
Hide file tree
Showing 23 changed files with 535 additions and 452 deletions.
346 changes: 180 additions & 166 deletions apiserver/plane/app/views/search/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,184 +253,198 @@ def get(self, request, slug):
class SearchEndpoint(BaseAPIView):
def get(self, request, slug, project_id):
query = request.query_params.get("query", False)
query_type = request.query_params.get("query_type", "user_mention")
query_types = request.query_params.get("query_type", "user_mention").split(",")
query_types = [qt.strip() for qt in query_types]
count = int(request.query_params.get("count", 5))

if query_type == "user_mention":
fields = ["member__first_name", "member__last_name", "member__display_name"]
q = Q()

if query:
for field in fields:
q |= Q(**{f"{field}__icontains": query})
users = (
ProjectMember.objects.filter(
q,
project__project_projectmember__member=self.request.user,
project__project_projectmember__is_active=True,
project_id=project_id,
workspace__slug=slug,
)
.annotate(
member__avatar_url=Case(
# If `avatar_asset` exists, use it to generate the asset URL
When(
member__avatar_asset__isnull=False,
then=Concat(
Value("/api/assets/v2/static/"),
"member__avatar_asset", # Assuming avatar_asset has an id or relevant field
Value("/"),
response_data = {}

for query_type in query_types:
if query_type == "user_mention":
fields = [
"member__first_name",
"member__last_name",
"member__display_name",
]
q = Q()

if query:
for field in fields:
q |= Q(**{f"{field}__icontains": query})
users = (
ProjectMember.objects.filter(
q,
project__project_projectmember__member=self.request.user,
project__project_projectmember__is_active=True,
project_id=project_id,
workspace__slug=slug,
)
.annotate(
member__avatar_url=Case(
When(
member__avatar_asset__isnull=False,
then=Concat(
Value("/api/assets/v2/static/"),
"member__avatar_asset",
Value("/"),
),
),
When(
member__avatar_asset__isnull=True, then="member__avatar"
),
),
# If `avatar_asset` is None, fall back to using `avatar` field directly
When(member__avatar_asset__isnull=True, then="member__avatar"),
default=Value(None),
output_field=models.CharField(),
default=Value(None),
output_field=models.CharField(),
)
)
.order_by("-created_at")
.values("member__avatar_url", "member__display_name", "member__id")[
:count
]
)
.order_by("-created_at")
.values("member__avatar_url", "member__display_name", "member__id")[
:count
]
)

return Response(users, status=status.HTTP_200_OK)
response_data["user_mention"] = list(users)

if query_type == "project":
fields = ["name", "identifier"]
q = Q()
elif query_type == "project":
fields = ["name", "identifier"]
q = Q()

if query:
for field in fields:
q |= Q(**{f"{field}__icontains": query})
projects = (
Project.objects.filter(
q,
Q(project_projectmember__member=self.request.user) | Q(network=2),
workspace__slug=slug,
if query:
for field in fields:
q |= Q(**{f"{field}__icontains": query})
projects = (
Project.objects.filter(
q,
Q(project_projectmember__member=self.request.user)
| Q(network=2),
workspace__slug=slug,
)
.order_by("-created_at")
.distinct()
.values(
"name", "id", "identifier", "logo_props", "workspace__slug"
)[:count]
)
.order_by("-created_at")
.distinct()
.values("name", "id", "identifier", "logo_props", "workspace__slug")[
:count
]
)
return Response(projects, status=status.HTTP_200_OK)

if query_type == "issue":
fields = ["name", "sequence_id", "project__identifier"]
q = Q()

if query:
for field in fields:
if field == "sequence_id":
# Match whole integers only (exclude decimal numbers)
sequences = re.findall(r"\b\d+\b", query)
for sequence_id in sequences:
q |= Q(**{"sequence_id": sequence_id})
else:
response_data["project"] = list(projects)

elif query_type == "issue":
fields = ["name", "sequence_id", "project__identifier"]
q = Q()

if query:
for field in fields:
if field == "sequence_id":
sequences = re.findall(r"\b\d+\b", query)
for sequence_id in sequences:
q |= Q(**{"sequence_id": sequence_id})
else:
q |= Q(**{f"{field}__icontains": query})

issues = (
Issue.issue_objects.filter(
q,
project__project_projectmember__member=self.request.user,
project__project_projectmember__is_active=True,
workspace__slug=slug,
project_id=project_id,
)
.order_by("-created_at")
.distinct()
.values(
"name",
"id",
"sequence_id",
"project__identifier",
"project_id",
"priority",
"state_id",
"type_id",
)[:count]
)
response_data["issue"] = list(issues)

elif query_type == "cycle":
fields = ["name"]
q = Q()

if query:
for field in fields:
q |= Q(**{f"{field}__icontains": query})

issues = (
Issue.issue_objects.filter(
q,
project__project_projectmember__member=self.request.user,
project__project_projectmember__is_active=True,
workspace__slug=slug,
project_id=project_id,
cycles = (
Cycle.objects.filter(
q,
project__project_projectmember__member=self.request.user,
project__project_projectmember__is_active=True,
workspace__slug=slug,
)
.order_by("-created_at")
.distinct()
.values(
"name",
"id",
"project_id",
"project__identifier",
"workspace__slug",
)[:count]
)
.order_by("-created_at")
.distinct()
.values(
"name",
"id",
"sequence_id",
"project__identifier",
"project_id",
"priority",
"state_id",
"type_id",
)[:count]
)
return Response(issues, status=status.HTTP_200_OK)

if query_type == "cycle":
fields = ["name"]
q = Q()

if query:
for field in fields:
q |= Q(**{f"{field}__icontains": query})

cycles = (
Cycle.objects.filter(
q,
project__project_projectmember__member=self.request.user,
project__project_projectmember__is_active=True,
workspace__slug=slug,
response_data["cycle"] = list(cycles)

elif query_type == "module":
fields = ["name"]
q = Q()

if query:
for field in fields:
q |= Q(**{f"{field}__icontains": query})

modules = (
Module.objects.filter(
q,
project__project_projectmember__member=self.request.user,
project__project_projectmember__is_active=True,
workspace__slug=slug,
)
.order_by("-created_at")
.distinct()
.values(
"name",
"id",
"project_id",
"project__identifier",
"status",
"workspace__slug",
)[:count]
)
.order_by("-created_at")
.distinct()
.values(
"name", "id", "project_id", "project__identifier", "workspace__slug"
)[:count]
)
return Response(cycles, status=status.HTTP_200_OK)

if query_type == "module":
fields = ["name"]
q = Q()

if query:
for field in fields:
q |= Q(**{f"{field}__icontains": query})

modules = (
Module.objects.filter(
q,
project__project_projectmember__member=self.request.user,
project__project_projectmember__is_active=True,
workspace__slug=slug,
response_data["module"] = list(modules)

elif query_type == "page":
fields = ["name"]
q = Q()

if query:
for field in fields:
q |= Q(**{f"{field}__icontains": query})

pages = (
Page.objects.filter(
q,
projects__project_projectmember__member=self.request.user,
projects__project_projectmember__is_active=True,
projects__id=project_id,
workspace__slug=slug,
access=0,
)
.order_by("-created_at")
.distinct()
.values(
"name", "id", "logo_props", "projects__id", "workspace__slug"
)[:count]
)
.order_by("-created_at")
.distinct()
.values(
"name",
"id",
"project_id",
"project__identifier",
"status",
"workspace__slug",
)[:count]
)
return Response(modules, status=status.HTTP_200_OK)

if query_type == "page":
fields = ["name"]
q = Q()

if query:
for field in fields:
q |= Q(**{f"{field}__icontains": query})

pages = (
Page.objects.filter(
q,
projects__project_projectmember__member=self.request.user,
projects__project_projectmember__is_active=True,
projects__id=project_id,
workspace__slug=slug,
access=0,
response_data["page"] = list(pages)

else:
return Response(
{"error": f"Invalid query type: {query_type}"},
status=status.HTTP_400_BAD_REQUEST,
)
.order_by("-created_at")
.distinct()
.values("name", "id", "logo_props", "projects__id", "workspace__slug")[
:count
]
)
return Response(pages, status=status.HTTP_200_OK)

return Response(
{"error": "Please provide a valid query"},
status=status.HTTP_400_BAD_REQUEST,
)
return Response(response_data, status=status.HTTP_200_OK)
Loading

0 comments on commit 760d415

Please sign in to comment.