gas-drf/gas_drf/permissions.py

16 lines
467 B
Python
Raw Permalink Normal View History

2022-03-21 17:48:13 +01:00
from rest_framework.permissions import BasePermission
class HasValidRole(BasePermission):
def has_permission(self, request, view):
user = request.user
roles = set(view.roles)
roles.add(view.base_role)
access_denied = (
not user.is_authenticated or (
not user.is_superuser
and not user.user_roles.filter(role__in=roles).exists()
)
)
return not access_denied