Skip to content

Commit

Permalink
feat: Provide filtering method to exclude deleted memberships
Browse files Browse the repository at this point in the history
  • Loading branch information
David Code Howard committed Oct 6, 2023
1 parent 3d2d852 commit 6acabd9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions terraso_backend/apps/graphql/schema/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 6acabd9

Please sign in to comment.