From 8704784f0bc7f2f494b9adc471fcb58f50197e51 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 8 Nov 2021 05:04:11 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Require=20the=20"Edit"=20permiss?= =?UTF-8?q?ion=20on=20sync,=20start,=20lock,=20unlock=20and=20stop=20actio?= =?UTF-8?q?ns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/sophon/notebooks/views.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/sophon/notebooks/views.py b/backend/sophon/notebooks/views.py index ff5d7ce..09c104d 100644 --- a/backend/sophon/notebooks/views.py +++ b/backend/sophon/notebooks/views.py @@ -4,10 +4,12 @@ import typing as t from django.db.models import Q from rest_framework import status from rest_framework.decorators import action +from rest_framework.permissions import BasePermission from rest_framework.request import Request from rest_framework.response import Response from sophon.core.models import ResearchGroup +from sophon.core.permissions import Edit from sophon.core.serializers import dynamic_serializer, NoneSerializer from sophon.core.views import SophonGroupViewSet from sophon.notebooks.models import Notebook @@ -18,6 +20,12 @@ class NotebooksViewSet(SophonGroupViewSet, metaclass=abc.ABCMeta): def get_group_from_serializer(self, serializer) -> ResearchGroup: return serializer.validated_data["project"].group + def get_permission_classes(self) -> t.Collection[t.Type[BasePermission]]: + if self.action in ["sync", "start", "lock", "unlock", "stop"]: + return Edit + else: + super().get_permission_classes() + 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)