From 6acabd94ae21c0d2616441ae70a9033002b2b552 Mon Sep 17 00:00:00 2001 From: David Code Howard Date: Fri, 6 Oct 2023 17:22:31 -0400 Subject: [PATCH] feat: Provide filtering method to exclude deleted memberships --- terraso_backend/apps/graphql/schema/users.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/terraso_backend/apps/graphql/schema/users.py b/terraso_backend/apps/graphql/schema/users.py index a0c406d56..9263b0f0d 100644 --- a/terraso_backend/apps/graphql/schema/users.py +++ b/terraso_backend/apps/graphql/schema/users.py @@ -16,12 +16,12 @@ import graphene import rules import structlog -from django_filters import FilterSet +from django_filters import CharFilter, FilterSet from graphene import relay from graphene_django import DjangoObjectType -from graphene_django.filter import TypedFilter from apps.auth.services import JWTService +from apps.collaboration.models import Membership from apps.core.models import User, UserPreference from apps.core.models.users import NOTIFICATION_KEYS from apps.graphql.exceptions import GraphQLNotAllowedException @@ -38,7 +38,7 @@ class UserFilter(FilterSet): - project = TypedFilter(field_name="collaboration_memberships__membership_list__project") + project = CharFilter(method="filter_user_in_project") class Meta: model = User @@ -48,6 +48,10 @@ class Meta: "last_name": ["icontains"], } + def filter_user_in_project(self, queryset, name, value): + memberships = Membership.objects.filter(membership_list__project=value) + return queryset.filter(collaboration_memberships__in=memberships) + class UserNode(DjangoObjectType): id = graphene.ID(source="pk", required=True)