aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/permissions.py
diff options
context:
space:
mode:
authorTom Christie2013-03-12 18:49:38 +0000
committerTom Christie2013-03-12 18:49:38 +0000
commite8db504a9802c6dcc111a327f681e01b9b3e2e16 (patch)
treecc85f273295484a0e145eee63b1f8d5af1701572 /rest_framework/permissions.py
parent12ac357559457d1ded341728aaf76408f0417f9b (diff)
parent20880232930dd6f3a1de9dda1546c84b9279a258 (diff)
downloaddjango-rest-framework-e8db504a9802c6dcc111a327f681e01b9b3e2e16.tar.bz2
Merge master
Diffstat (limited to 'rest_framework/permissions.py')
-rw-r--r--rest_framework/permissions.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/rest_framework/permissions.py b/rest_framework/permissions.py
index c477474c..92f8215a 100644
--- a/rest_framework/permissions.py
+++ b/rest_framework/permissions.py
@@ -104,6 +104,8 @@ class DjangoModelPermissions(BasePermission):
'DELETE': ['%(app_label)s.delete_%(model_name)s'],
}
+ authenticated_users_only = True
+
def get_required_permissions(self, method, model_cls):
"""
Given a model and an HTTP method, return the list of permission
@@ -117,13 +119,18 @@ class DjangoModelPermissions(BasePermission):
def has_permission(self, request, view):
model_cls = getattr(view, 'model', None)
- if not model_cls:
- return True
+ queryset = getattr(view, 'queryset', None)
+
+ if model_cls is None and queryset is not None:
+ model_cls = queryset.model
+
+ assert model_cls, ('Cannot apply DjangoModelPermissions on a view that'
+ ' does not have `.model` or `.queryset` property.')
perms = self.get_required_permissions(request.method, model_cls)
if (request.user and
- request.user.is_authenticated() and
+ (request.user.is_authenticated() or not self.authenticated_users_only) and
request.user.has_perms(perms)):
return True
return False