From e01940ad147d2b710a8590be085f537e4bcd52a6 Mon Sep 17 00:00:00 2001 From: helllllllder Date: Tue, 22 Oct 2024 17:07:58 -0300 Subject: [PATCH] feat: add new filters on room list feat: remove is_active filter from room endpoint as it will only work for active rooms --- chats/apps/api/v1/rooms/filters.py | 17 ++++++----------- chats/apps/api/v1/rooms/viewsets.py | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/chats/apps/api/v1/rooms/filters.py b/chats/apps/api/v1/rooms/filters.py index dbb323f3..d28322e2 100644 --- a/chats/apps/api/v1/rooms/filters.py +++ b/chats/apps/api/v1/rooms/filters.py @@ -12,7 +12,7 @@ class RoomFilter(filters.FilterSet): class Meta: model = Room - fields = ["queue", "is_active"] + fields = ["queue", "is_waiting"] project = filters.CharFilter( field_name="project", @@ -21,11 +21,9 @@ class Meta: help_text=_("Project's UUID"), ) - is_active = filters.BooleanFilter( - field_name="is_active", + attending = filters.BooleanFilter( required=False, - method="filter_is_active", - help_text=_("Is active?"), + method="filter_attending", ) def filter_project(self, queryset, name, value): @@ -43,17 +41,14 @@ def filter_project(self, queryset, name, value): if project_permission.is_admin: user_filter = Q(user=user) | Q(user__isnull=True) - return queryset.filter( - user_filter, is_active=True, queue__in=project_permission.queue_ids - ) + return queryset.filter(user_filter, queue__in=project_permission.queue_ids) user_project = Q(user=user) & Q(project_uuid=value) queue_filter = Q(user__isnull=True) & Q(queue__in=project_permission.queue_ids) ff = user_project | queue_filter queryset = queryset.filter( ff, - is_active=True, ) return queryset - def filter_is_active(self, queryset, name, value): - return queryset.filter(is_active=value) + def filter_attending(self, queryset, name, value): + return queryset.filter(user__isnull=not value) diff --git a/chats/apps/api/v1/rooms/viewsets.py b/chats/apps/api/v1/rooms/viewsets.py index 38824666..eb092fcd 100644 --- a/chats/apps/api/v1/rooms/viewsets.py +++ b/chats/apps/api/v1/rooms/viewsets.py @@ -44,7 +44,7 @@ class RoomViewset( mixins.UpdateModelMixin, GenericViewSet, ): - queryset = Room.objects.all() + queryset = Room.objects.filter(is_active=True) serializer_class = RoomSerializer filter_backends = [ DjangoFilterBackend,