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): """