Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beat.web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
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
beat
beat.web
Commits
2bea7add
Commit
2bea7add
authored
4 years ago
by
Samuel GAIST
Browse files
Options
Downloads
Patches
Plain Diff
[search][api] Move from permissions mixin to use permissions
parent
672d7678
No related branches found
No related tags found
1 merge request
!327
Refactor update creation api
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
beat/web/search/api.py
+10
-10
10 additions, 10 deletions
beat/web/search/api.py
with
10 additions
and
10 deletions
beat/web/search/api.py
+
10
−
10
View file @
2bea7add
...
@@ -38,7 +38,7 @@ from django.utils import six
...
@@ -38,7 +38,7 @@ from django.utils import six
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
from
rest_framework.views
import
APIView
from
rest_framework.views
import
APIView
from
rest_framework
import
permissions
from
rest_framework
import
permissions
as
drf_permissions
from
rest_framework
import
generics
from
rest_framework
import
generics
from
rest_framework
import
status
from
rest_framework
import
status
...
@@ -49,12 +49,12 @@ from ..experiments.models import Experiment
...
@@ -49,12 +49,12 @@ from ..experiments.models import Experiment
from
..toolchains.models
import
Toolchain
from
..toolchains.models
import
Toolchain
from
..common.models
import
Shareable
from
..common.models
import
Shareable
from
..common.mixins
import
IsAuthorOrReadOnlyMixin
from
..common.api
import
ShareView
from
..common.api
import
ShareView
from
..common.utils
import
ensure_html
from
..common.utils
import
ensure_html
from
..common.responses
import
BadRequestResponse
from
..common.responses
import
BadRequestResponse
from
..common.mixins
import
CommonContextMixin
,
SerializerFieldsMixin
from
..common.mixins
import
CommonContextMixin
,
SerializerFieldsMixin
from
..common.utils
import
py3_cmp
from
..common.utils
import
py3_cmp
from
..common
import
permissions
as
beat_permissions
from
..ui.templatetags.gravatar
import
gravatar_hash
from
..ui.templatetags.gravatar
import
gravatar_hash
...
@@ -86,7 +86,7 @@ class SearchView(APIView):
...
@@ -86,7 +86,7 @@ class SearchView(APIView):
"""
"""
permission_classes
=
[
permissions
.
AllowAny
]
permission_classes
=
[
drf_
permissions
.
AllowAny
]
FILTER_IEXACT
=
0
FILTER_IEXACT
=
0
FILTER_ICONTAINS
=
1
FILTER_ICONTAINS
=
1
...
@@ -555,7 +555,7 @@ class SearchSaveView(
...
@@ -555,7 +555,7 @@ class SearchSaveView(
"""
"""
model
=
Search
model
=
Search
permission_classes
=
[
permissions
.
IsAuthenticated
]
permission_classes
=
[
drf_
permissions
.
IsAuthenticated
]
serializer_class
=
SearchWriteSerializer
serializer_class
=
SearchWriteSerializer
def
build_results
(
self
,
request
,
search
):
def
build_results
(
self
,
request
,
search
):
...
@@ -599,7 +599,7 @@ class ListSearchView(CommonContextMixin, generics.ListAPIView):
...
@@ -599,7 +599,7 @@ class ListSearchView(CommonContextMixin, generics.ListAPIView):
Lists all available search from a user
Lists all available search from a user
"""
"""
permission_classes
=
[
permissions
.
AllowAny
]
permission_classes
=
[
drf_
permissions
.
AllowAny
]
serializer_class
=
SearchSerializer
serializer_class
=
SearchSerializer
def
get_queryset
(
self
):
def
get_queryset
(
self
):
...
@@ -615,10 +615,7 @@ class ListSearchView(CommonContextMixin, generics.ListAPIView):
...
@@ -615,10 +615,7 @@ class ListSearchView(CommonContextMixin, generics.ListAPIView):
class
RetrieveDestroySearchAPIView
(
class
RetrieveDestroySearchAPIView
(
CommonContextMixin
,
CommonContextMixin
,
SerializerFieldsMixin
,
generics
.
RetrieveDestroyAPIView
SerializerFieldsMixin
,
IsAuthorOrReadOnlyMixin
,
generics
.
RetrieveDestroyAPIView
,
):
):
"""
"""
Delete the given search
Delete the given search
...
@@ -626,6 +623,7 @@ class RetrieveDestroySearchAPIView(
...
@@ -626,6 +623,7 @@ class RetrieveDestroySearchAPIView(
model
=
Search
model
=
Search
serializer_class
=
SearchSerializer
serializer_class
=
SearchSerializer
permission_classes
=
[
beat_permissions
.
IsAuthorOrReadOnly
]
def
get_object
(
self
):
def
get_object
(
self
):
author_name
=
self
.
kwargs
.
get
(
"
author_name
"
)
author_name
=
self
.
kwargs
.
get
(
"
author_name
"
)
...
@@ -639,6 +637,8 @@ class RetrieveDestroySearchAPIView(
...
@@ -639,6 +637,8 @@ class RetrieveDestroySearchAPIView(
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
search
=
self
.
get_object
()
search
=
self
.
get_object
()
self
.
check_object_permissions
(
request
,
search
)
# Process the query string
# Process the query string
allow_sharing
=
request
.
user
==
search
.
author
allow_sharing
=
request
.
user
==
search
.
author
...
@@ -659,7 +659,7 @@ class ShareSearchView(ShareView):
...
@@ -659,7 +659,7 @@ class ShareSearchView(ShareView):
"""
"""
model
=
Search
model
=
Search
permission_classes
=
[
permissions
.
AllowAny
]
permission_classes
=
[
drf_
permissions
.
AllowAny
]
def
get_queryset
(
self
):
def
get_queryset
(
self
):
self
.
kwargs
[
"
version
"
]
=
1
self
.
kwargs
[
"
version
"
]
=
1
...
...
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