【发布时间】:2014-08-04 16:47:28
【问题描述】:
以下权限不生效IsOwnerOrReadOnly我不明白为什么:
class PermissionMixin(object):
"""
API Permission Mixin.
Permission checks authentication information in the request.user and request.auth
properties to determine if the incoming request should be permitted.
"""
permission_classes = [Or(permissions.IsAdminUser, TokenHasReadWriteScope), And (IsOwnerOrReadOnly)]
我希望允许 IsAdminUser 或 TokenHasReadWriteScope 用户,但始终检查他们是所有者 IsOwnerOrReadOnly。
class IsOwnerOrReadOnly(permissions.BasePermission):
"""
Custom permission to only allow owners of an object to edit it.
"""
def has_object_permission(self, request, view, obj):
# Read permissions are allowed to any request,
# so we'll always allow GET, HEAD or OPTIONS requests.
if request.method in permissions.SAFE_METHODS:
return True
# Write permissions are only allowed to the owner of object.
return obj.user == request.user
【问题讨论】:
标签: python django django-rest-framework