Repository: openfun/marsha

Issue:
Refactor django permissions
## Feature Request

**Is your feature request related to a problem or unsupported use case? Please describe.**

In PR #234 

> I think the permission classes `IsRelatedVideoTokenOrAdminUser` and `IsVideoTokenOrAdminUser` have bad names. They are looking for Instructor tokens as opposed to the `IsVideoToken` class which accepts students.

**Describe the solution you'd like**

> Should we call them something like `IsVideoInstructorTokenOrAdminUser` et `IsVideoRelatedInstructorTokenOrAdminUser`?





Discussion:

Resolving patch:
diff --git a/src/backend/marsha/core/api.py b/src/backend/marsha/core/api.py
--- a/src/backend/marsha/core/api.py
+++ b/src/backend/marsha/core/api.py
@@ -25,9 +25,9 @@
 from .lti import LTIUser
 from .models import Thumbnail, TimedTextTrack, Video
 from .permissions import (
-    IsRelatedVideoTokenOrAdminUser,
+    IsVideoInstructorTokenOrAdminUser,
+    IsVideoRelatedInstructorTokenOrAdminUser,
     IsVideoToken,
-    IsVideoTokenOrAdminUser,
 )
 from .serializers import (
     ThumbnailSerializer,
@@ -116,7 +116,7 @@ class VideoViewSet(
 
     queryset = Video.objects.all()
     serializer_class = VideoSerializer
-    permission_classes = [IsVideoTokenOrAdminUser]
+    permission_classes = [IsVideoInstructorTokenOrAdminUser]
 
     @action(methods=["post"], detail=True, url_path="initiate-upload")
     # pylint: disable=unused-argument
@@ -181,7 +181,7 @@ def get_permissions(self):
         if self.action == "metadata":
             permission_classes = [IsVideoToken]
         else:
-            permission_classes = [IsRelatedVideoTokenOrAdminUser]
+            permission_classes = [IsVideoRelatedInstructorTokenOrAdminUser]
         return [permission() for permission in permission_classes]
 
     def get_queryset(self):
@@ -240,7 +240,7 @@ class ThumbnailViewSet(
 ):
     """Viewset for the API of the Thumbnail object."""
 
-    permission_classes = [IsRelatedVideoTokenOrAdminUser]
+    permission_classes = [IsVideoRelatedInstructorTokenOrAdminUser]
     serializer_class = ThumbnailSerializer
 
     def get_queryset(self):
diff --git a/src/backend/marsha/core/permissions.py b/src/backend/marsha/core/permissions.py
--- a/src/backend/marsha/core/permissions.py
+++ b/src/backend/marsha/core/permissions.py
@@ -5,7 +5,7 @@
 from .models.account import INSTRUCTOR, LTI_ROLES
 
 
-class IsVideoTokenOrAdminUser(permissions.IsAdminUser):
+class IsVideoInstructorTokenOrAdminUser(permissions.IsAdminUser):
     """A custom permission class for JWT Tokens related to a video object.
 
     These permissions build on the `IsAdminUser` class but grants additional specific accesses
@@ -95,7 +95,7 @@ def has_object_permission(self, request, view, obj):
         return super().has_object_permission(request, view, obj)
 
 
-class IsRelatedVideoTokenOrAdminUser(IsVideoTokenOrAdminUser):
+class IsVideoRelatedInstructorTokenOrAdminUser(IsVideoInstructorTokenOrAdminUser):
     """A custom permission class for JWT Tokens related to objects linked to a video.
 
     These permissions build on the `IsAdminUser` class but grants additional specific accesses


Test patch: