Add admin only permission for api

This commit is contained in:
Aroy-Art 2025-01-03 22:42:02 +01:00
parent 622cb351b7
commit 9a3a1cf60b
Signed by: Aroy
GPG key ID: 583642324A1D2070

View file

@ -1,6 +1,15 @@
# permissions.py
from rest_framework import permissions
def check_admin(user):
"""check for admin permission for restricted views"""
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)