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
cb8d94b9
Commit
cb8d94b9
authored
Feb 11, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve docstring on DjangoModelPermissions, and also ensure the user is authenticated.
parent
2c11fd68
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
6 deletions
+9
-6
djangorestframework/permissions.py
+9
-6
No files found.
djangorestframework/permissions.py
View file @
cb8d94b9
...
...
@@ -91,15 +91,18 @@ class IsUserOrIsAnonReadOnly(BasePermission):
class
DjangoModelPermissions
(
BasePermission
):
"""
The request is authenticated
against the Django user's permissions on the
`Resource`'s `Model`.
The request is authenticated
using `django.contrib.auth` permissions.
See: https://docs.djangoproject.com/en/dev/topics/auth/#permissions
This permission should only be used on views with a `ModelResource`.
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`.
"""
# Map methods into required permission codes.
# Override this if you need to also provide 'read' permissions,
# or
other custom behaviour
.
# or
if you want to provide custom permisson codes
.
perms_map
=
{
'GET'
:
[],
'OPTIONS'
:
[],
...
...
@@ -117,7 +120,7 @@ class DjangoModelPermissions(BasePermission):
"""
kwargs
=
{
'app_label'
:
model_cls
.
_meta
.
app_label
,
'model_name'
:
model_cls
.
_
_name__
.
lower
()
'model_name'
:
model_cls
.
_
meta
.
module_name
}
try
:
return
[
perm
%
kwargs
for
perm
in
self
.
perms_map
[
method
]]
...
...
@@ -129,7 +132,7 @@ class DjangoModelPermissions(BasePermission):
model_cls
=
self
.
view
.
resource
.
model
perms
=
self
.
get_required_permissions
(
method
,
model_cls
)
if
not
user
.
has_perms
(
perms
):
if
not
user
.
is_authenticated
or
not
user
.
has_perms
(
perms
):
raise
_403_FORBIDDEN_RESPONSE
...
...
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