From 8df23945230019c81492cbaf10f15c9591d5c453 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 20 Oct 2021 21:34:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20NoneSerializer=20being=20u?= =?UTF-8?q?sed=20in=20actions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/sophon/core/views.py | 6 ++++++ backend/sophon/notebooks/views.py | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/backend/sophon/core/views.py b/backend/sophon/core/views.py index 8c63f36..2943ece 100644 --- a/backend/sophon/core/views.py +++ b/backend/sophon/core/views.py @@ -207,6 +207,12 @@ class ResearchGroupViewSet(WriteSophonViewSet): "owner": self.request.user, } + def get_custom_serializer_classes(self): + if self.action in ["join", "leave"]: + return self.get_object().get_access_serializer(self.request.user) + else: + return serializers.NoneSerializer + @action(detail=True, methods=["post"], name="Join group") def join(self, request, pk) -> Response: group = models.ResearchGroup.objects.get(pk=pk) diff --git a/backend/sophon/notebooks/views.py b/backend/sophon/notebooks/views.py index 2c1bdfc..ab94ce6 100644 --- a/backend/sophon/notebooks/views.py +++ b/backend/sophon/notebooks/views.py @@ -8,7 +8,7 @@ from rest_framework.request import Request from rest_framework.response import Response from sophon.core.models import ResearchGroup -from sophon.core.serializers import dynamic_serializer +from sophon.core.serializers import dynamic_serializer, NoneSerializer from sophon.core.views import SophonGroupViewSet from sophon.notebooks.models import Notebook from sophon.projects.models import ResearchProject @@ -18,6 +18,12 @@ class NotebooksViewSet(SophonGroupViewSet, metaclass=abc.ABCMeta): def get_group_from_serializer(self, serializer) -> ResearchGroup: return serializer.validated_data["project"].group + def get_custom_serializer_classes(self): + if self.action in ["sync", "start", "lock", "unlock", "stop"]: + return self.get_object().get_access_serializer(self.request.user) + else: + return NoneSerializer + @action(["PATCH"], detail=True) def sync(self, request: Request, **kwargs): """