From 2cead7a5e72c34ea26f09a754a627228cd647f74 Mon Sep 17 00:00:00 2001
From: Konrad Mohrfeldt <konrad.mohrfeldt@farbdev.org>
Date: Wed, 6 Sep 2023 14:40:51 +0200
Subject: [PATCH] feat: implement search filter for User REST endpoint

We need the search filter to implement a user complete field in the
dashboard.
---
 program/views.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/program/views.py b/program/views.py
index ec2ec57b..ecdabf3e 100644
--- a/program/views.py
+++ b/program/views.py
@@ -25,6 +25,7 @@ from itertools import pairwise
 from textwrap import dedent
 
 from drf_spectacular.utils import OpenApiResponse, extend_schema, extend_schema_view
+from rest_framework import filters as drf_filters
 from rest_framework import mixins, permissions, status, viewsets
 from rest_framework.exceptions import ValidationError
 from rest_framework.pagination import LimitOffsetPagination
@@ -263,6 +264,8 @@ class APIUserViewSet(
     permission_classes = [permissions.DjangoModelPermissionsOrAnonReadOnly]
     serializer_class = UserSerializer
     queryset = User.objects.all()
+    filter_backends = [drf_filters.SearchFilter]
+    search_fields = ["username", "first_name", "last_name", "email"]
 
     def get_queryset(self):
         queryset = super().get_queryset()
-- 
GitLab