-
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.
- Loading branch information
Showing
3 changed files
with
25 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from rest_framework.permissions import IsAuthenticated, SAFE_METHODS | ||
from authentication.models import User | ||
|
||
# (Almost) same as StudentPermission | ||
class TeacherPermission(IsAuthenticated): | ||
|
||
def has_permission(self, request, view): | ||
"""Check if user has permission to view a general Teacher endpoint.""" | ||
user: User = request.user | ||
if view.action in ['list', 'create', 'update', 'partial_update', 'destroy']: | ||
return False | ||
return True | ||
|
||
def has_object_permission(self, request, view, obj): | ||
"""Check if user has permission to view a detailed group endpoint""" | ||
user: User = request.user | ||
return request.method in SAFE_METHODS and user.id == request.user.id |
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
8cb3bcc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
closing #124