From d47799e6eef0e4212ef6328ab0d1551b76752e3b Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Tue, 22 Dec 2020 12:42:54 +0100 Subject: [PATCH] More API filters for the permission app --- apps/member/api/views.py | 4 ++-- apps/permission/api/views.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/member/api/views.py b/apps/member/api/views.py index 8e08aad7..8c48cfea 100644 --- a/apps/member/api/views.py +++ b/apps/member/api/views.py @@ -53,8 +53,8 @@ class MembershipViewSet(ReadProtectedModelViewSet): filterset_fields = ['club__name', 'club__email', 'club__note__alias__name', 'club__note__alias__normalized_name', 'user__username', 'user__last_name', 'user__first_name', 'user__email', 'user__note__alias__name', 'user__note__alias__normalized_name', - 'date_start', 'date_end', 'fee', ] + 'date_start', 'date_end', 'fee', 'roles', ] ordering_fields = ['id', 'date_start', 'date_end', ] search_fields = ['$club__name', '$club__email', '$club__note__alias__name', '$club__note__alias__normalized_name', '$user__username', '$user__last_name', '$user__first_name', '$user__email', - '$user__note__alias__name', '$user__note__alias__normalized_name', ] + '$user__note__alias__name', '$user__note__alias__normalized_name', '$roles__name', ] diff --git a/apps/permission/api/views.py b/apps/permission/api/views.py index 1ec67aa3..a2ba8b7a 100644 --- a/apps/permission/api/views.py +++ b/apps/permission/api/views.py @@ -2,6 +2,8 @@ # SPDX-License-Identifier: GPL-3.0-or-later from django_filters.rest_framework import DjangoFilterBackend +from rest_framework.filters import SearchFilter + from api.viewsets import ReadOnlyProtectedModelViewSet from .serializers import PermissionSerializer, RoleSerializer @@ -16,8 +18,9 @@ class PermissionViewSet(ReadOnlyProtectedModelViewSet): """ queryset = Permission.objects.all() serializer_class = PermissionSerializer - filter_backends = [DjangoFilterBackend] - filterset_fields = ['model', 'type', ] + filter_backends = [DjangoFilterBackend, SearchFilter] + filterset_fields = ['model', 'type', 'query', 'mask', 'field', 'permanent', ] + search_fields = ['$model__name', '$query', '$description', ] class RoleViewSet(ReadOnlyProtectedModelViewSet): @@ -28,5 +31,6 @@ class RoleViewSet(ReadOnlyProtectedModelViewSet): """ queryset = Role.objects.all() serializer_class = RoleSerializer - filter_backends = [DjangoFilterBackend] - filterset_fields = ['role', ] + filter_backends = [DjangoFilterBackend, SearchFilter] + filterset_fields = ['name', 'permissions', 'for_club', 'membership_set__user', ] + SearchFilter = ['$name', '$for_club__name', ]