filter /api/v2/users/N/tokens/ to only show tokens for _that_ user

see: https://github.com/ansible/tower/issues/1773
This commit is contained in:
Ryan Petrello
2018-05-17 13:16:48 -04:00
parent 46add35f98
commit 51f66b8c0a
3 changed files with 23 additions and 2 deletions

View File

@@ -15,7 +15,7 @@ from awx.api.views import (
UserActivityStreamList,
UserAccessList,
OAuth2ApplicationList,
OAuth2TokenList,
OAuth2UserTokenList,
OAuth2PersonalTokenList,
UserAuthorizedTokenList,
)
@@ -32,7 +32,7 @@ urls = [
url(r'^(?P<pk>[0-9]+)/activity_stream/$', UserActivityStreamList.as_view(), name='user_activity_stream_list'),
url(r'^(?P<pk>[0-9]+)/access_list/$', UserAccessList.as_view(), name='user_access_list'),
url(r'^(?P<pk>[0-9]+)/applications/$', OAuth2ApplicationList.as_view(), name='o_auth2_application_list'),
url(r'^(?P<pk>[0-9]+)/tokens/$', OAuth2TokenList.as_view(), name='o_auth2_token_list'),
url(r'^(?P<pk>[0-9]+)/tokens/$', OAuth2UserTokenList.as_view(), name='o_auth2_token_list'),
url(r'^(?P<pk>[0-9]+)/authorized_tokens/$', UserAuthorizedTokenList.as_view(), name='user_authorized_token_list'),
url(r'^(?P<pk>[0-9]+)/personal_tokens/$', OAuth2PersonalTokenList.as_view(), name='o_auth2_personal_token_list'),

View File

@@ -1598,6 +1598,18 @@ class OAuth2TokenList(ListCreateAPIView):
model = OAuth2AccessToken
serializer_class = OAuth2TokenSerializer
swagger_topic = 'Authentication'
class OAuth2UserTokenList(SubListCreateAPIView):
view_name = _("OAuth2 User Tokens")
model = OAuth2AccessToken
serializer_class = OAuth2TokenSerializer
parent_model = User
relationship = 'main_oauth2accesstoken'
parent_key = 'user'
swagger_topic = 'Authentication'
class OAuth2AuthorizedTokenList(SubListCreateAPIView):