diff options
| author | Tom Christie | 2012-08-24 20:57:10 +0100 |
|---|---|---|
| committer | Tom Christie | 2012-08-24 20:57:10 +0100 |
| commit | 87b363f7bc5f73d850df123a61895d65ec0b05e7 (patch) | |
| tree | 1993adba1ad6a01c498c883babb157e3b4c7ee15 /djangorestframework | |
| parent | 4e4584a01a4cf67c23aec21088110cd477ba841b (diff) | |
| download | django-rest-framework-87b363f7bc5f73d850df123a61895d65ec0b05e7.tar.bz2 | |
Remove PermissionsMixin
Diffstat (limited to 'djangorestframework')
| -rw-r--r-- | djangorestframework/mixins.py | 30 | ||||
| -rw-r--r-- | djangorestframework/tests/authentication.py | 2 | ||||
| -rw-r--r-- | djangorestframework/tests/renderers.py | 1 | ||||
| -rw-r--r-- | djangorestframework/tests/throttling.py | 14 | ||||
| -rw-r--r-- | djangorestframework/views.py | 17 |
5 files changed, 24 insertions, 40 deletions
diff --git a/djangorestframework/mixins.py b/djangorestframework/mixins.py index d1014a84..28fa5847 100644 --- a/djangorestframework/mixins.py +++ b/djangorestframework/mixins.py @@ -15,7 +15,6 @@ from djangorestframework.response import Response, ImmediateResponse __all__ = ( # Base behavior mixins - 'PermissionsMixin', 'ResourceMixin', # Model behavior mixins 'ReadModelMixin', @@ -27,35 +26,6 @@ __all__ = ( ) -########## Permissions Mixin ########## - -class PermissionsMixin(object): - """ - Simple :class:`mixin` class to add permission checking to a :class:`View` class. - """ - - permissions_classes = () - """ - The set of permissions that will be enforced on this view. - - Should be a tuple/list of classes as described in the :mod:`permissions` module. - """ - - def get_permissions(self): - """ - Instantiates and returns the list of permissions that this view requires. - """ - return [p(self) for p in self.permissions_classes] - - # TODO: wrap this behavior around dispatch() - def check_permissions(self, user): - """ - Check user permissions and either raise an ``ImmediateResponse`` or return. - """ - for permission in self.get_permissions(): - permission.check_permission(user) - - ########## Resource Mixin ########## class ResourceMixin(object): diff --git a/djangorestframework/tests/authentication.py b/djangorestframework/tests/authentication.py index 5debc79a..24c59488 100644 --- a/djangorestframework/tests/authentication.py +++ b/djangorestframework/tests/authentication.py @@ -12,7 +12,7 @@ import base64 class MockView(View): - permissions_classes = (permissions.IsAuthenticated,) + permission_classes = (permissions.IsAuthenticated,) def post(self, request): return HttpResponse({'a': 1, 'b': 2, 'c': 3}) diff --git a/djangorestframework/tests/renderers.py b/djangorestframework/tests/renderers.py index 0e160606..610457c7 100644 --- a/djangorestframework/tests/renderers.py +++ b/djangorestframework/tests/renderers.py @@ -4,7 +4,6 @@ from django.conf.urls.defaults import patterns, url, include from django.test import TestCase from djangorestframework import status -from djangorestframework.compat import View as DjangoView from djangorestframework.response import Response from djangorestframework.views import View from djangorestframework.renderers import BaseRenderer, JSONRenderer, YAMLRenderer, \ diff --git a/djangorestframework/tests/throttling.py b/djangorestframework/tests/throttling.py index 73a4c02b..8c5457d3 100644 --- a/djangorestframework/tests/throttling.py +++ b/djangorestframework/tests/throttling.py @@ -12,25 +12,28 @@ from djangorestframework.permissions import PerUserThrottling, PerViewThrottling from djangorestframework.resources import FormResource from djangorestframework.response import Response + class MockView(View): - permissions_classes = ( PerUserThrottling, ) + permission_classes = (PerUserThrottling,) throttle = '3/sec' def get(self, request): return Response('foo') + class MockView_PerViewThrottling(MockView): - permissions_classes = ( PerViewThrottling, ) + permission_classes = (PerViewThrottling,) + class MockView_PerResourceThrottling(MockView): - permissions_classes = ( PerResourceThrottling, ) + permission_classes = (PerResourceThrottling,) resource = FormResource + class MockView_MinuteThrottling(MockView): throttle = '3/min' - class ThrottlingTests(TestCase): urls = 'djangorestframework.tests.throttling' @@ -54,7 +57,7 @@ class ThrottlingTests(TestCase): """ Explicitly set the timer, overriding time.time() """ - view.permissions_classes[0].timer = lambda self: value + view.permission_classes[0].timer = lambda self: value def test_request_throttling_expires(self): """ @@ -101,7 +104,6 @@ class ThrottlingTests(TestCase): """ self.ensure_is_throttled(MockView_PerResourceThrottling, 503) - def ensure_response_header_contains_proper_throttle_field(self, view, expected_headers): """ Ensure the response returns an X-Throttle field with status and next attributes diff --git a/djangorestframework/views.py b/djangorestframework/views.py index f6a7a3bf..2ce36a9a 100644 --- a/djangorestframework/views.py +++ b/djangorestframework/views.py @@ -68,7 +68,7 @@ _resource_classes = ( ) -class View(ResourceMixin, PermissionsMixin, DjangoView): +class View(ResourceMixin, DjangoView): """ Handles incoming requests and maps them to REST operations. Performs request deserialization, response serialization, authentication and input validation. @@ -96,7 +96,7 @@ class View(ResourceMixin, PermissionsMixin, DjangoView): List of all authenticating methods to attempt. """ - permissions = (permissions.FullAnonAccess,) + permission_classes = (permissions.FullAnonAccess,) """ List of all permissions that must be checked. """ @@ -223,6 +223,19 @@ class View(ResourceMixin, PermissionsMixin, DjangoView): """ return self.renderers[0] + def get_permissions(self): + """ + Instantiates and returns the list of permissions that this view requires. + """ + return [permission(self) for permission in self.permission_classes] + + def check_permissions(self, user): + """ + Check user permissions and either raise an ``ImmediateResponse`` or return. + """ + for permission in self.get_permissions(): + permission.check_permission(user) + def initial(self, request, *args, **kargs): """ This method is a hook for any code that needs to run prior to |
