Better search endpoints schema

This commit is contained in:
shamoon 2024-11-30 21:22:58 -08:00
parent 313431ead8
commit a92dd74a42
2 changed files with 46 additions and 7 deletions

@ -442,7 +442,7 @@ class TagSerializerVersion1(MatchingModelSerializer, OwnedObjectSerializer):
class TagSerializer(MatchingModelSerializer, OwnedObjectSerializer):
def get_text_color(self, obj):
def get_text_color(self, obj) -> str:
try:
h = obj.color.lstrip("#")
rgb = tuple(int(h[i : i + 2], 16) / 256 for i in (0, 2, 4))
@ -1003,7 +1003,7 @@ class DocumentSerializer(
# return full permissions if we're doing a PATCH or PUT
context = kwargs.get("context")
if (
if context is not None and (
context.get("request").method == "PATCH"
or context.get("request").method == "PUT"
):

@ -1558,6 +1558,45 @@ class SearchAutoCompleteView(GenericAPIView):
)
@extend_schema_view(
get=extend_schema(
description="Global search",
parameters=[
OpenApiParameter(
name="query",
required=True,
type=str,
description="Query to search for",
),
OpenApiParameter(
name="db_only",
required=False,
type=bool,
description="Search only the database",
),
],
responses={
(200, "application/json"): inline_serializer(
name="SearchResult",
fields={
"total": serializers.IntegerField(),
"documents": DocumentSerializer(many=True),
"saved_views": SavedViewSerializer(many=True),
"tags": TagSerializer(many=True),
"correspondents": CorrespondentSerializer(many=True),
"document_types": DocumentTypeSerializer(many=True),
"storage_paths": StoragePathSerializer(many=True),
"users": UserSerializer(many=True),
"groups": GroupSerializer(many=True),
"mail_rules": MailRuleSerializer(many=True),
"mail_accounts": MailAccountSerializer(many=True),
"workflows": WorkflowSerializer(many=True),
"custom_fields": CustomFieldSerializer(many=True),
},
),
},
),
)
class GlobalSearchView(PassUserMixin):
permission_classes = (IsAuthenticated,)
serializer_class = SearchResultSerializer