-
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 branch 'api-working' of https://github.com/SELab-2/UGent-1 into…
… api-working
- Loading branch information
Showing
3 changed files
with
53 additions
and
2 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,18 @@ | ||
from rest_framework import permissions | ||
|
||
from backend.pigeonhole.apps.users.models import User | ||
|
||
|
||
class UserPermissions(permissions.BasePermission): | ||
def has_permission(self, request, view): | ||
if request.user.is_admin or request.user.is_superuser: | ||
return True # TODO can admins destroy each other? | ||
|
||
if request.user.is_teacher or request.user.is_student: | ||
if view.action in ['list', 'retrieve']: # TODO: can teachers create and destroy users? | ||
return True | ||
elif view.action in ['update', 'partial_update', 'destroy'] and User.objects.filter( | ||
id=request.user.id).exists(): | ||
return True | ||
|
||
return False |
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