from rest_framework.permissions import BasePermission def _get_user_type(user): if not user or not user.is_authenticated: return None profile = getattr(user, "profile", None) if profile: return profile.user_type return "administrator" if user.is_staff else "user" class IsAdministrator(BasePermission): def has_permission(self, request, view): return _get_user_type(request.user) == "administrator" class IsNotPublico(BasePermission): def has_permission(self, request, view): user_type = _get_user_type(request.user) return user_type is not None and user_type != "publico" class IsPublico(BasePermission): def has_permission(self, request, view): return _get_user_type(request.user) == "publico"