From 155683d3ccc74dffc88f1a658e169b4a20a72104 Mon Sep 17 00:00:00 2001 From: EwoutV Date: Fri, 8 Mar 2024 14:46:29 +0100 Subject: [PATCH] chore: linting --- backend/api/permissions/course_permissions.py | 5 +++-- backend/api/permissions/role_permissions.py | 5 ++++- backend/api/views/course_view.py | 3 +-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/backend/api/permissions/course_permissions.py b/backend/api/permissions/course_permissions.py index e2f7d987..46ee6f50 100644 --- a/backend/api/permissions/course_permissions.py +++ b/backend/api/permissions/course_permissions.py @@ -29,11 +29,12 @@ def has_object_permission(self, request: Request, view: ViewSet, course: Course) return request.user.is_authenticated # We only allow teachers and assistants to modify specified courses. - role: Teacher|Assistant = user.teacher or user.assistant + role: Teacher | Assistant = user.teacher or user.assistant return role is not None and \ role.courses.filter(id=course.id).exists() + class CourseTeacherPermission(CoursePermission): """Permission class for teacher-only course endpoints.""" def has_object_permission(self, request: Request, view: ViewSet, course: Course) -> bool: @@ -44,4 +45,4 @@ def has_object_permission(self, request: Request, view: ViewSet, course: Course) return request.user.is_authenticated return user.teacher.exists() and \ - user.teacher.courses.filter(id=course.id).exists() \ No newline at end of file + user.teacher.courses.filter(id=course.id).exists() diff --git a/backend/api/permissions/role_permissions.py b/backend/api/permissions/role_permissions.py index 2a023a9d..94ace65c 100644 --- a/backend/api/permissions/role_permissions.py +++ b/backend/api/permissions/role_permissions.py @@ -3,6 +3,7 @@ from api.models.assistant import Assistant from api.models.teacher import Teacher + class IsStudent(IsAuthenticated): def has_permission(self, request, view): """Returns true if the request contains a user, @@ -10,6 +11,7 @@ def has_permission(self, request, view): return super().has_permission(request, view) and \ Student.objects.filter(id=request.user.id).exists() + class IsTeacher(IsAuthenticated): def has_permission(self, request, view): """Returns true if the request contains a user, @@ -17,9 +19,10 @@ def has_permission(self, request, view): return super().has_permission(request, view) and \ Teacher.objects.filter(id=request.user.id).exists() + class IsAssistant(IsAuthenticated): def has_permission(self, request, view): """Returns true if the request contains a user, with said user being a student""" return super().has_permission(request, view) and \ - Assistant.objects.filter(id=request.user.id).exists() \ No newline at end of file + Assistant.objects.filter(id=request.user.id).exists() diff --git a/backend/api/views/course_view.py b/backend/api/views/course_view.py index bf4320d2..c7123fa1 100644 --- a/backend/api/views/course_view.py +++ b/backend/api/views/course_view.py @@ -76,7 +76,6 @@ def assistants(self, request: Request, **_) -> Response: # Not found raise NotFound(gettext("assistants.error.404")) - @action(detail=True, methods=["get"]) def students(self, request, **_): """Returns a list of students for the given course""" @@ -113,4 +112,4 @@ def join(self, request, **_): return Response({ "message": gettext("courses.success.join") - }) \ No newline at end of file + })