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
110d5494
Commit
110d5494
authored
Aug 23, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1034 from KrzysiekJ/patch-create-fallback-removal
PATCH requests should not be able to create objects.
parents
95b2bf50
e677f3ee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
5 deletions
+19
-5
rest_framework/mixins.py
+8
-5
rest_framework/tests/test_generics.py
+11
-0
No files found.
rest_framework/mixins.py
View file @
110d5494
...
...
@@ -142,11 +142,14 @@ class UpdateModelMixin(object):
try
:
return
self
.
get_object
()
except
Http404
:
# If this is a PUT-as-create operation, we need to ensure that
# we have relevant permissions, as if this was a POST request.
# This will either raise a PermissionDenied exception,
# or simply return None
self
.
check_permissions
(
clone_request
(
self
.
request
,
'POST'
))
if
self
.
request
.
method
==
'PUT'
:
# For PUT-as-create operation, we need to ensure that we have
# relevant permissions, as if this was a POST request. This
# will either raise a PermissionDenied exception, or simply
# return None.
self
.
check_permissions
(
clone_request
(
self
.
request
,
'POST'
))
else
:
raise
def
pre_save
(
self
,
obj
):
"""
...
...
rest_framework/tests/test_generics.py
View file @
110d5494
...
...
@@ -338,6 +338,17 @@ class TestInstanceView(TestCase):
new_obj
=
SlugBasedModel
.
objects
.
get
(
slug
=
'test_slug'
)
self
.
assertEqual
(
new_obj
.
text
,
'foobar'
)
def
test_patch_cannot_create_an_object
(
self
):
"""
PATCH requests should not be able to create objects.
"""
data
=
{
'text'
:
'foobar'
}
request
=
factory
.
patch
(
'/999'
,
data
,
format
=
'json'
)
with
self
.
assertNumQueries
(
1
):
response
=
self
.
view
(
request
,
pk
=
999
)
.
render
()
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_404_NOT_FOUND
)
self
.
assertFalse
(
self
.
objects
.
filter
(
id
=
999
)
.
exists
())
class
TestOverriddenGetObject
(
TestCase
):
"""
...
...
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