Skip to content

Commit 91f1236

Browse files
committed
ORing object permissions falls back to has_permission if no object permission
Composing permissions with OR should fall back on has_permission when has_object_permission isn't implemented. If has_object_permission is not implemented, than its has_permission should apply to all objects. Strictly speaking, BasePermission.has_object_permission could return self.has_permission(request, view), but only in the OR case is it possible that wasn't already true, so only doing that fallback in the OR case saves some redundant calls to has_permission.
1 parent 0edc4d7 commit 91f1236

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

rest_framework/permissions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,13 @@ def has_permission(self, request, view):
8181

8282
def has_object_permission(self, request, view, obj):
8383
hasperm1 = self.op1.has_object_permission(request, view, obj)
84+
if hasperm1 is NotImplemented:
85+
hasperm1 = self.op1.has_permission(request, view)
8486
if hasperm1 and hasperm1 is not NotImplemented:
8587
return hasperm1
8688
hasperm2 = self.op2.has_object_permission(request, view, obj)
89+
if hasperm2 is NotImplemented:
90+
hasperm2 = self.op2.has_permission(request, view)
8791
return hasperm1 if hasperm2 is NotImplemented else hasperm2
8892

8993

0 commit comments

Comments
 (0)