10000 Do not extend AND/OR/NOT from BasePermission · coderanger/django-rest-framework@e709378 · GitHub
[go: up one dir, main page]

Skip to content

Commit e709378

Browse files
committed
Do not extend AND/OR/NOT from BasePermission
This can be done in a separate pull request, but it was reverted out of this one because it made it more difficult to review and increased its chances of not being accepted.
1 parent 9c3ea30 commit e709378

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

rest_framework/permissions.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,7 @@ def __call__(self, *args, **kwargs):
4747
return self.operator_class(op1, op2)
4848

4949

50-
class BasePermissionMetaclass(OperationHolderMixin, type):
51-
pass
52-
53-
54-
class BasePermission(metaclass=BasePermissionMetaclass):
55-
"""
56-
A base class from which all permission classes should inherit.
57-
"""
58-
59-
def has_permission(self, request, view):
60-
"""
61-
Return `True` if permission is granted, `False` otherwise.
62-
"""
63-
return True
64-
65-
def has_object_permission(self, request, view, obj):
66-
"""
67-
Return `True` if permission is granted, `False` otherwise.
68-
"""
69-
return True
70-
71-
72-
class AND(BasePermission):
50+
class AND:
7351
def __init__(self, *args):
7452
self.permissions = args
7553

@@ -86,7 +64,7 @@ def has_object_permission(self, request, view, obj):
8664
return True
8765

8866

89-
class OR(BasePermission):
67+
class OR:
9068
def __init__(self, *args):
9169
self.permissions = args
9270

@@ -103,7 +81,7 @@ def has_object_permission(self, request, view, obj):
10381
return False
10482

10583

106-
class NOT(BasePermission):
84+
class NOT:
10785
def __init__(self, op1):
10886
self.op1 = op1
10987

@@ -114,6 +92,28 @@ def has_object_permission(self, request, view, obj):
11492
return not self.op1.has_object_permission(request, view, obj)
11593

11694

95+
class BasePermissionMetaclass(OperationHolderMixin, type):
96+
pass
97+
98+
99+
class BasePermission(metaclass=BasePermissionMetaclass):
100+
"""
101+
A base class from which all permission classes should inherit.
102+
"""
103+
104+
def has_permission(self, request, view):
105+
"""
106+
Return `True` if permission is granted, `False` otherwise.
107+
"""
108+
return True
109+
110+
def has_object_permission(self, request, view, obj):
111+
"""
112+
Return `True` if permission is granted, `False` otherwise.
113+
"""
114+
return True
115+
116+
117117
class AllowAny(BasePermission):
118118
"""
119119
Allow any access.

0 commit comments

Comments
 (0)
0