From bdb9d9e272a328037207493947b5a5f71f8e4438 Mon Sep 17 00:00:00 2001 From: EwoutV Date: Fri, 8 Mar 2024 20:52:00 +0100 Subject: [PATCH] chore: linting --- backend/api/permissions/course_permissions.py | 4 ++++ backend/api/permissions/role_permissions.py | 3 +++ backend/api/views/course_view.py | 1 - 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/api/permissions/course_permissions.py b/backend/api/permissions/course_permissions.py index fd0c0f9c..3c2543b5 100644 --- a/backend/api/permissions/course_permissions.py +++ b/backend/api/permissions/course_permissions.py @@ -8,6 +8,7 @@ class CoursePermission(BasePermission): """Permission class used as default policy for course endpoints.""" + def has_permission(self, request: Request, view: ViewSet) -> bool: """Check if user has permission to view a general course endpoint.""" user: User = request.user @@ -34,6 +35,7 @@ def has_object_permission(self, request: Request, view: ViewSet, course: Course) class CourseAssistantPermission(CoursePermission): """Permission class for assistant related endpoints.""" + def has_object_permission(self, request: Request, view: ViewSet, course: Course) -> bool: user: User = request.user @@ -47,6 +49,7 @@ def has_object_permission(self, request: Request, view: ViewSet, course: Course) class CourseStudentPermission(CoursePermission): """Permission class for student related endpoints.""" + def has_object_permission(self, request: Request, view: ViewSet, course: Course): user: User = request.user @@ -64,6 +67,7 @@ def has_object_permission(self, request: Request, view: ViewSet, course: Course) class CourseProjectPermission(CoursePermission): """Permission class for project related endpoints.""" + def has_object_permission(self, request: Request, view: ViewSet, course: Course): user: User = request.user diff --git a/backend/api/permissions/role_permissions.py b/backend/api/permissions/role_permissions.py index b196747c..1e9c275c 100644 --- a/backend/api/permissions/role_permissions.py +++ b/backend/api/permissions/role_permissions.py @@ -9,12 +9,15 @@ def is_student(user: User): return Student.objects.filter(id=user.id).exists() + def is_assistant(user: User): return Assistant.objects.filter(id=user.id).exists() + def is_teacher(user: User): return Teacher.objects.filter(id=user.id).exists() + class IsStudent(IsAuthenticated): def has_permission(self, request: Request, view): """Returns true if the request contains a user, diff --git a/backend/api/views/course_view.py b/backend/api/views/course_view.py index 13dfbae4..416ab1f5 100644 --- a/backend/api/views/course_view.py +++ b/backend/api/views/course_view.py @@ -77,7 +77,6 @@ def _remove_assistant(self, request: Request, **_): # Not found raise NotFound(gettext("assistants.error.404")) - @action(detail=True, methods=["get"], permission_classes=[IsAdminUser | CourseStudentPermission]) def students(self, request, **_): """Returns a list of students for the given course"""