Skip to content

Commit

Permalink
chore: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
EwoutV committed Mar 8, 2024
1 parent 009895e commit 155683d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions backend/api/permissions/course_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
user.teacher.courses.filter(id=course.id).exists()
5 changes: 4 additions & 1 deletion backend/api/permissions/role_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@
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,
with said user being a student"""
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,
with said user being a student"""
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()
Assistant.objects.filter(id=request.user.id).exists()
3 changes: 1 addition & 2 deletions backend/api/views/course_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -113,4 +112,4 @@ def join(self, request, **_):

return Response({
"message": gettext("courses.success.join")
})
})

0 comments on commit 155683d

Please sign in to comment.