You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
570 B

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