aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/permissions.py
diff options
context:
space:
mode:
authorTom Christie2012-10-15 13:27:50 +0100
committerTom Christie2012-10-15 13:27:50 +0100
commit9c1fba3483b7e81da0744464dcf23a5f12711de2 (patch)
treed9370dc9fb9d2fea65192bf5ce4d7fb594d3ad0c /rest_framework/permissions.py
parente88ca9637bd4f49659dd80ca7afd0f38adf07746 (diff)
downloaddjango-rest-framework-9c1fba3483b7e81da0744464dcf23a5f12711de2.tar.bz2
Tweak parsers to take parser_context
Diffstat (limited to 'rest_framework/permissions.py')
-rw-r--r--rest_framework/permissions.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/rest_framework/permissions.py b/rest_framework/permissions.py
index 13ea39ea..6f848cee 100644
--- a/rest_framework/permissions.py
+++ b/rest_framework/permissions.py
@@ -1,8 +1,5 @@
"""
-The :mod:`permissions` module bundles a set of permission classes that are used
-for checking if a request passes a certain set of constraints.
-
-Permission behavior is provided by mixing the :class:`mixins.PermissionsMixin` class into a :class:`View` class.
+Provides a set of pluggable permission policies.
"""
@@ -16,7 +13,7 @@ class BasePermission(object):
def has_permission(self, request, view, obj=None):
"""
- Should simply return, or raise an :exc:`response.ImmediateResponse`.
+ Return `True` if permission is granted, `False` otherwise.
"""
raise NotImplementedError(".has_permission() must be overridden.")
@@ -64,7 +61,8 @@ class DjangoModelPermissions(BasePermission):
It ensures that the user is authenticated, and has the appropriate
`add`/`change`/`delete` permissions on the model.
- This permission should only be used on views with a `ModelResource`.
+ This permission will only be applied against view classes that
+ provide a `.model` attribute, such as the generic class-based views.
"""
# Map methods into required permission codes.
@@ -92,7 +90,10 @@ class DjangoModelPermissions(BasePermission):
return [perm % kwargs for perm in self.perms_map[method]]
def has_permission(self, request, view, obj=None):
- model_cls = view.model
+ model_cls = getattr(view, 'model', None)
+ if not model_cls:
+ return True
+
perms = self.get_required_permissions(request.method, model_cls)
if (request.user and