Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
PEDASI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Research Software Group
PEDASI
Commits
f081f2d2
Commit
f081f2d2
authored
6 years ago
by
James Graham
Browse files
Options
Downloads
Patches
Plain Diff
Add necessary permission checks to metadata item API endpoints
parent
79715c6d
Branches
dev
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/permissions.py
+14
-0
14 additions, 0 deletions
api/permissions.py
api/views/datasources.py
+8
-3
8 additions, 3 deletions
api/views/datasources.py
with
22 additions
and
3 deletions
api/permissions.py
+
14
−
0
View file @
f081f2d2
...
@@ -87,3 +87,17 @@ class IsAdminOrReadOnly(permissions.BasePermission):
...
@@ -87,3 +87,17 @@ class IsAdminOrReadOnly(permissions.BasePermission):
request
.
method
in
permissions
.
SAFE_METHODS
or
request
.
method
in
permissions
.
SAFE_METHODS
or
request
.
user
.
is_superuser
request
.
user
.
is_superuser
)
)
class
IsOwnerOrReadOnly
(
permissions
.
BasePermission
):
"""
Grant owner and admins write access - all others get read-only.
"""
message
=
'
You do not have permission to access this resource.
'
def
has_permission
(
self
,
request
,
view
):
return
bool
(
request
.
method
in
permissions
.
SAFE_METHODS
or
view
.
get_datasource
().
owner
==
request
.
user
or
request
.
user
.
is_superuser
)
This diff is collapsed.
Click to expand it.
api/views/datasources.py
+
8
−
3
View file @
f081f2d2
...
@@ -21,15 +21,20 @@ from provenance import models as prov_models
...
@@ -21,15 +21,20 @@ from provenance import models as prov_models
class
MetadataItemApiViewset
(
viewsets
.
ModelViewSet
):
class
MetadataItemApiViewset
(
viewsets
.
ModelViewSet
):
"""
API ViewSet for viewing and managing dynamic metadata items on a data sources.
"""
serializer_class
=
serializers
.
MetadataItemSerializer
serializer_class
=
serializers
.
MetadataItemSerializer
permission_classes
=
[
permissions
.
IsAdminOrReadOnly
]
permission_classes
=
[
permissions
.
IsOwnerOrReadOnly
]
def
get_datasource
(
self
):
return
get_object_or_404
(
models
.
DataSource
,
pk
=
self
.
kwargs
[
'
datasource_pk
'
])
def
get_queryset
(
self
):
def
get_queryset
(
self
):
return
models
.
MetadataItem
.
objects
.
filter
(
datasource
=
self
.
kwargs
[
'
datasource_pk
'
])
return
models
.
MetadataItem
.
objects
.
filter
(
datasource
=
self
.
kwargs
[
'
datasource_pk
'
])
def
perform_create
(
self
,
serializer
):
def
perform_create
(
self
,
serializer
):
datasource
=
get_object_or_404
(
models
.
DataSource
,
pk
=
self
.
kwargs
[
'
datasource_pk
'
])
serializer
.
save
(
datasource
=
self
.
get_datasource
())
serializer
.
save
(
datasource
=
datasource
)
class
DataSourceApiViewset
(
viewsets
.
ReadOnlyModelViewSet
):
class
DataSourceApiViewset
(
viewsets
.
ReadOnlyModelViewSet
):
...
...
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