Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Metagenomics
metagenedb
Commits
9821e311
Commit
9821e311
authored
Dec 05, 2019
by
Kenzo-Hugo Hillion
♻
Browse files
add permissions for all to list only
parent
4643e950
Pipeline
#19355
failed with stages
in 0 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
backend/metagenedb/api/catalog/views/bulk_viewset.py
View file @
9821e311
...
...
@@ -3,11 +3,13 @@ from rest_framework import status
from
rest_framework.response
import
Response
from
rest_framework.viewsets
import
ModelViewSet
from
metagenedb.common.django_default.permissions
import
ListAndRetrieveAll
from
metagenedb.common.django_default.qparams_validators
import
PaginatedQueryParams
class
BulkViewSet
(
ModelViewSet
):
query_params_parser
=
PaginatedQueryParams
permission_classes
=
[
ListAndRetrieveAll
]
def
get_objects
(
self
,
instance_ids
):
return
self
.
queryset
.
in_bulk
(
instance_ids
,
field_name
=
self
.
lookup_field
)
...
...
backend/metagenedb/common/django_default/permissions.py
0 → 100644
View file @
9821e311
from
rest_framework.permissions
import
BasePermission
class
ListAndRetrieveAll
(
BasePermission
):
"""
Custom permission to only allow access to lists for admins
"""
def
has_permission
(
self
,
request
,
view
):
return
view
.
action
in
[
'list'
,
'retrieve'
]
or
request
.
user
.
is_staff
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment