Add admin only permission for api
This commit is contained in:
parent
622cb351b7
commit
9a3a1cf60b
1 changed files with 9 additions and 0 deletions
|
@ -1,6 +1,15 @@
|
||||||
# permissions.py
|
# permissions.py
|
||||||
|
from rest_framework import permissions
|
||||||
|
|
||||||
|
|
||||||
def check_admin(user):
|
def check_admin(user):
|
||||||
"""check for admin permission for restricted views"""
|
"""check for admin permission for restricted views"""
|
||||||
return user.is_staff or user.groups.filter(name="admin").exists()
|
return user.is_staff or user.groups.filter(name="admin").exists()
|
||||||
|
|
||||||
|
|
||||||
|
class AdminOnly(permissions.BasePermission):
|
||||||
|
"""allow only admin"""
|
||||||
|
|
||||||
|
def has_permission(self, request, view):
|
||||||
|
return check_admin(request.user)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue