Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djangoldp
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fay Arnold
djangoldp
Commits
2e0be9be
Commit
2e0be9be
authored
4 years ago
by
Calum Mackervoy
Browse files
Options
Downloads
Patches
Plain Diff
is_valid_create method on LDPViewSet
parent
b6ac3c93
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
djangoldp/views.py
+10
-0
10 additions, 0 deletions
djangoldp/views.py
with
10 additions
and
0 deletions
djangoldp/views.py
+
10
−
0
View file @
2e0be9be
...
...
@@ -343,9 +343,19 @@ class LDPViewSet(LDPViewSetGenerator):
return
type
(
LDPSerializer
)(
self
.
model
.
_meta
.
object_name
.
lower
()
+
name_prefix
+
'
Serializer
'
,
(
LDPSerializer
,),
{
'
Meta
'
:
meta_class
})
def
is_safe_create
(
self
,
user
,
validated_data
,
*
args
,
**
kwargs
):
'''
A function which is checked before the create operation to confirm the validated data is safe to add
returns True by default
:return: True if the operation should be permitted, False to return a 403 response
'''
return
True
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
serializer
=
self
.
get_write_serializer
(
data
=
request
.
data
)
serializer
.
is_valid
(
raise_exception
=
True
)
if
not
self
.
is_safe_create
(
request
.
user
,
serializer
.
validated_data
):
return
Response
({
'
detail
'
:
'
You do not have permission to perform this action
'
},
status
=
status
.
HTTP_403_FORBIDDEN
)
self
.
perform_create
(
serializer
)
response_serializer
=
self
.
get_serializer
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment