
* api: use DjangoQL for searches Signed-off-by: Jens Langhammer <jens@goauthentik.io> * expand search input and use textarea for multiline Signed-off-by: Jens Langhammer <jens@goauthentik.io> * start implementing autocomplete Signed-off-by: Jens Langhammer <jens@goauthentik.io> * only use ql for events Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make QL search opt in Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make pretend json relation work Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix schema Signed-off-by: Jens Langhammer <jens@goauthentik.io> * test Signed-off-by: Jens Langhammer <jens@goauthentik.io> * format Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make autocomplete l1 work Signed-off-by: Jens Langhammer <jens@goauthentik.io> * use forked js lib with types, separate QL Signed-off-by: Jens Langhammer <jens@goauthentik.io> * first attempt at making it fit our UI Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make dark theme somewhat work, fix search Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make more parts work Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make auto complete box be under cursor Signed-off-by: Jens Langhammer <jens@goauthentik.io> Co-authored-by: ripplefcl <github@ripple.contact> * remove django autocomplete for now Signed-off-by: Jens Langhammer <jens@goauthentik.io> * re-add event filtering Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix search when no ql is enabled Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make meta+enter submit, fix colour Signed-off-by: Jens Langhammer <jens@goauthentik.io> * make dark theme Signed-off-by: Jens Langhammer <jens@goauthentik.io> * formatting Signed-off-by: Jens Langhammer <jens@goauthentik.io> * enterprise Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * add tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * Update authentik/enterprise/search/apps.py Co-authored-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> Signed-off-by: Jens L. <jens@beryju.org> * add json element autocomplete Signed-off-by: Jens Langhammer <jens@goauthentik.io> Co-authored-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> Co-authored-by: ripplefcl <github@ripple.contact> * format Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix query Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix search reset Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix dark theme Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io> Signed-off-by: Jens L. <jens@beryju.org> Co-authored-by: ripplefcl <github@ripple.contact> Co-authored-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
54 lines
2.0 KiB
Python
54 lines
2.0 KiB
Python
from rest_framework.response import Response
|
|
|
|
from authentik.api.pagination import Pagination
|
|
from authentik.enterprise.search.ql import AUTOCOMPLETE_COMPONENT_NAME, QLSearch
|
|
|
|
|
|
class AutocompletePagination(Pagination):
|
|
|
|
def paginate_queryset(self, queryset, request, view=None):
|
|
self.view = view
|
|
return super().paginate_queryset(queryset, request, view)
|
|
|
|
def get_autocomplete(self):
|
|
schema = QLSearch().get_schema(self.request, self.view)
|
|
introspections = {}
|
|
if hasattr(self.view, "get_ql_fields"):
|
|
from authentik.enterprise.search.schema import AKQLSchemaSerializer
|
|
|
|
introspections = AKQLSchemaSerializer().serialize(
|
|
schema(self.page.paginator.object_list.model)
|
|
)
|
|
return introspections
|
|
|
|
def get_paginated_response(self, data):
|
|
previous_page_number = 0
|
|
if self.page.has_previous():
|
|
previous_page_number = self.page.previous_page_number()
|
|
next_page_number = 0
|
|
if self.page.has_next():
|
|
next_page_number = self.page.next_page_number()
|
|
return Response(
|
|
{
|
|
"pagination": {
|
|
"next": next_page_number,
|
|
"previous": previous_page_number,
|
|
"count": self.page.paginator.count,
|
|
"current": self.page.number,
|
|
"total_pages": self.page.paginator.num_pages,
|
|
"start_index": self.page.start_index(),
|
|
"end_index": self.page.end_index(),
|
|
},
|
|
"results": data,
|
|
"autocomplete": self.get_autocomplete(),
|
|
}
|
|
)
|
|
|
|
def get_paginated_response_schema(self, schema):
|
|
final_schema = super().get_paginated_response_schema(schema)
|
|
final_schema["properties"]["autocomplete"] = {
|
|
"$ref": f"#/components/schemas/{AUTOCOMPLETE_COMPONENT_NAME}"
|
|
}
|
|
final_schema["required"].append("autocomplete")
|
|
return final_schema
|