Skip to content

Commit ecb37f5

Browse files
committed
Merge pull request #2818 from maryokhin/master
Don't check for deprecated '.model' attribute in permissions
2 parents c6657da + 1ddfef1 commit ecb37f5

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

rest_framework/permissions.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class DjangoModelPermissions(BasePermission):
7777
`add`/`change`/`delete` permissions on the model.
7878
7979
This permission can only be applied against view classes that
80-
provide a `.model` or `.queryset` attribute.
80+
provide a `.queryset` attribute.
8181
"""
8282

8383
# Map methods into required permission codes.
@@ -107,24 +107,19 @@ def get_required_permissions(self, method, model_cls):
107107
return [perm % kwargs for perm in self.perms_map[method]]
108108

109109
def has_permission(self, request, view):
110-
# Note that `.model` attribute on views is deprecated, although we
111-
# enforce the deprecation on the view `get_serializer_class()` and
112-
# `get_queryset()` methods, rather than here.
113-
model_cls = getattr(view, 'model', None)
114110
queryset = getattr(view, 'queryset', None)
115111

116-
if model_cls is None and queryset is not None:
117-
model_cls = queryset.model
118-
119112
# Workaround to ensure DjangoModelPermissions are not applied
120113
# to the root view when using DefaultRouter.
121-
if model_cls is None and getattr(view, '_ignore_model_permissions', False):
114+
if queryset is None and getattr(view, '_ignore_model_permissions', False):
122115
return True
123116

124-
assert model_cls, ('Cannot apply DjangoModelPermissions on a view that'
125-
' does not have `.model` or `.queryset` property.')
117+
assert queryset, (
118+
'Cannot apply DjangoModelPermissions on a view that '
119+
'does not have `.queryset` property.'
120+
)
126121

127-
perms = self.get_required_permissions(request.method, model_cls)
122+
perms = self.get_required_permissions(request.method, queryset.model)
128123

129124
return (
130125
request.user and
@@ -150,7 +145,7 @@ class DjangoObjectPermissions(DjangoModelPermissions):
150145
`add`/`change`/`delete` permissions on the object using .has_perms.
151146
152147
This permission can only be applied against view classes that
153-
provide a `.model` or `.queryset` attribute.
148+
provide a `.queryset` attribute.
154149
"""
155150

156151
perms_map = {
@@ -171,14 +166,10 @@ def get_required_object_permissions(self, method, model_cls):
171166
return [perm % kwargs for perm in self.perms_map[method]]
172167

173168
def has_object_permission(self, request, view, obj):
174-
model_cls = getattr(view, 'model', None)
175-
queryset = getattr(view, 'queryset', None)
176-
177-
if model_cls is None and queryset is not None:
178-
model_cls = queryset.model
169+
model_cls = view.queryset.model
170+
user = request.user
179171

180172
perms = self.get_required_object_permissions(request.method, model_cls)
181-
user = request.user
182173

183174
if not user.has_perms(perms, obj):
184175
# If the user does not have permissions we need to determine if

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy