-
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.
Merge pull request #131 from SELab-2/permissions_cleanup
Permissions cleanup
- Loading branch information
Showing
7 changed files
with
45 additions
and
9 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,15 @@ | ||
from rest_framework.permissions import IsAuthenticated, SAFE_METHODS | ||
from api.permissions.role_permissions import is_teacher | ||
from authentication.models import User | ||
|
||
|
||
class StudentPermission(IsAuthenticated): | ||
|
||
def has_permission(self, request, view): | ||
"""Check if user has permission to view a general student endpoint.""" | ||
return view.action == 'retrieve' | ||
|
||
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 or is_teacher(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
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.""" | ||
return view.action == 'retrieve' | ||
|
||
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
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