-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: finished course logic with sensible permissions
- Loading branch information
Showing
4 changed files
with
134 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,36 @@ | ||
from rest_framework.permissions import IsAuthenticated | ||
from rest_framework.request import Request | ||
from authentication.models import User | ||
from api.models.student import Student | ||
from api.models.assistant import Assistant | ||
from api.models.teacher import Teacher | ||
|
||
|
||
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, view): | ||
def has_permission(self, request: 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() | ||
return super().has_permission(request, view) and is_student(request.user) | ||
|
||
|
||
class IsTeacher(IsAuthenticated): | ||
def has_permission(self, request, view): | ||
def has_permission(self, request: 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() | ||
return super().has_permission(request, view) and is_teacher(request.user) | ||
|
||
|
||
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() | ||
return super().has_permission(request, view) and is_assistant(request.user) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters