from rest_framework.permissions import BasePermission class IsDiveBaseAdmin(BasePermission): """ Allows access only to admins or superusers. """ def has_permission(self, request, view): return bool(request.user and request.user.is_authenticated and request.user.role == "ADMIN" or request.user.is_superuser) class IsSameDiveBase(BasePermission): """ Allows access only to objects in the same dive base as the user. """ def has_object_permission(self, request, view, obj): return obj.dive_base == request.user.dive_base