From d2defa41796abf8aa0849192bf124e7d2032f083 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 10 Oct 2021 16:44:19 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Return=20the=20joined=20/=20left?= =?UTF-8?q?=20group?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/sophon/core/views.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/backend/sophon/core/views.py b/backend/sophon/core/views.py index 2203ac6..da36a86 100644 --- a/backend/sophon/core/views.py +++ b/backend/sophon/core/views.py @@ -2,14 +2,13 @@ import abc import typing as t import deprecation -import pkg_resources from django.contrib.auth.models import User -from rest_framework.views import APIView -from rest_framework.viewsets import ModelViewSet, ReadOnlyModelViewSet +from rest_framework import status as s +from rest_framework.decorators import action from rest_framework.response import Response from rest_framework.serializers import Serializer -from rest_framework.decorators import action -from rest_framework import status as s +from rest_framework.views import APIView +from rest_framework.viewsets import ModelViewSet, ReadOnlyModelViewSet from . import models from . import permissions @@ -223,7 +222,11 @@ class ResearchGroupViewSet(WriteSophonViewSet): # Add the user to the group group.members.add(self.request.user) - return Response(status=s.HTTP_200_OK) + # noinspection PyPep8Naming + Serializer = group.get_access_serializer(self.request.user) + serializer = Serializer(instance=group) + + return Response(data=serializer.data, status=s.HTTP_200_OK) @action(detail=True, methods=["delete"], name="Leave group") def leave(self, request, pk): @@ -240,7 +243,11 @@ class ResearchGroupViewSet(WriteSophonViewSet): # Add the user to the group group.members.remove(self.request.user) - return Response(status=s.HTTP_200_OK) + # noinspection PyPep8Naming + Serializer = group.get_access_serializer(self.request.user) + serializer = Serializer(instance=group) + + return Response(data=serializer.data, status=s.HTTP_200_OK) class SophonGroupViewSet(WriteSophonViewSet, metaclass=abc.ABCMeta):