Merge "Delete all user tokens method"

This commit is contained in:
Jenkins 2015-04-09 08:26:42 +00:00 committed by Gerrit Code Review
commit e23f3b1a76
3 changed files with 29 additions and 0 deletions

View File

@ -39,6 +39,8 @@ LOG = log.getLogger(__name__)
class UserTokensController(rest.RestController):
_custom_actions = {"delete_all": ["DELETE"]}
def _from_db_model(self, access_token):
access_token_model = wmodels.AccessToken.from_db_model(
access_token,
@ -203,6 +205,17 @@ class UserTokensController(rest.RestController):
token_api.user_token_delete(access_token_id)
@decorators.db_exceptions
@secure(checks.authenticated)
@wsme_pecan.wsexpose(wmodels.AccessToken, int, status_code=204)
def delete_all(self, user_id):
"""Deletes all access tokens for the given user
:param user_id: The user ID of the user.
"""
token_api.delete_all_user_tokens(user_id)
def _assert_can_access(self, user_id, token_entity=None):
current_user = user_api.user_get(request.current_user_id)

View File

@ -82,3 +82,10 @@ def user_token_update(access_token_id, values):
def user_token_delete(access_token_id):
access_tokens_api.access_token_delete(access_token_id)
def delete_all_user_tokens(user_id):
access_tokens = access_tokens_api.access_token_get_all(user_id=user_id)
for token in access_tokens:
access_tokens_api.access_token_delete(token.id)

View File

@ -68,6 +68,15 @@ class TestUserTokensAsUser(base.FunctionalTest):
self.assertIsNotNone(response.json['id'],
read_response['id'])
def test_delete_all_user_tokens(self):
"""Assert that user may delete all his tokens
"""
resource = self.resource + "/delete_all"
self.delete(resource)
response = self.get_json(self.resource, expect_errors=True)
self.assertEqual(401, response.status_code)
def test_create_access_token_autofill(self):
"""Assert that creating a token without the access_token parameter
generates a randomly generated access token.