Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
87b363f7
Commit
87b363f7
authored
Aug 24, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove PermissionsMixin
parent
4e4584a0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
40 deletions
+24
-40
djangorestframework/mixins.py
+0
-30
djangorestframework/tests/authentication.py
+1
-1
djangorestframework/tests/renderers.py
+0
-1
djangorestframework/tests/throttling.py
+8
-6
djangorestframework/views.py
+15
-2
No files found.
djangorestframework/mixins.py
View file @
87b363f7
...
...
@@ -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
):
...
...
djangorestframework/tests/authentication.py
View file @
87b363f7
...
...
@@ -12,7 +12,7 @@ import base64
class
MockView
(
View
):
permission
s
_classes
=
(
permissions
.
IsAuthenticated
,)
permission_classes
=
(
permissions
.
IsAuthenticated
,)
def
post
(
self
,
request
):
return
HttpResponse
({
'a'
:
1
,
'b'
:
2
,
'c'
:
3
})
...
...
djangorestframework/tests/renderers.py
View file @
87b363f7
...
...
@@ -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
,
\
...
...
djangorestframework/tests/throttling.py
View file @
87b363f7
...
...
@@ -12,25 +12,28 @@ from djangorestframework.permissions import PerUserThrottling, PerViewThrottling
from
djangorestframework.resources
import
FormResource
from
djangorestframework.response
import
Response
class
MockView
(
View
):
permission
s_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
):
permission
s_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
.
permission
s
_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
...
...
djangorestframework/views.py
View file @
87b363f7
...
...
@@ -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
_classe
s
=
(
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment