mirror of https://github.com/zulip/zulip.git
Support API for changing user's API key.
(imported from commit b9f5594cf809965c996115c8420a359820dad3ff)
This commit is contained in:
parent
0b4c37ef8d
commit
164215bc78
|
@ -509,6 +509,19 @@ class StreamMessagesTest(AuthedTestCase):
|
||||||
self.assert_stream_message(non_ascii_stream_name, subject=u"hümbüǵ",
|
self.assert_stream_message(non_ascii_stream_name, subject=u"hümbüǵ",
|
||||||
content=u"hümbüǵ")
|
content=u"hümbüǵ")
|
||||||
|
|
||||||
|
class UserChangesTest(AuthedTestCase):
|
||||||
|
def test_update_api_key(self):
|
||||||
|
email = "hamlet@zulip.com"
|
||||||
|
self.login(email)
|
||||||
|
user = get_user_profile_by_email(email)
|
||||||
|
old_api_key = user.api_key
|
||||||
|
result = self.client.post('/json/users/me/api_key/regenerate')
|
||||||
|
self.assert_json_success(result)
|
||||||
|
new_api_key = ujson.loads(result.content)['api_key']
|
||||||
|
self.assertNotEqual(old_api_key, new_api_key)
|
||||||
|
user = get_user_profile_by_email(email)
|
||||||
|
self.assertEqual(new_api_key, user.api_key)
|
||||||
|
|
||||||
class BotTest(AuthedTestCase):
|
class BotTest(AuthedTestCase):
|
||||||
def assert_num_bots_equal(self, count):
|
def assert_num_bots_equal(self, count):
|
||||||
result = self.client.post("/json/get_bots")
|
result = self.client.post("/json/get_bots")
|
||||||
|
|
|
@ -2109,6 +2109,15 @@ def patch_bot_backend(request, user_profile, email, full_name=REQ):
|
||||||
)
|
)
|
||||||
return json_success(json_result)
|
return json_success(json_result)
|
||||||
|
|
||||||
|
@has_request_variables
|
||||||
|
def regenerate_api_key(request, user_profile):
|
||||||
|
user_profile.api_key = random_api_key()
|
||||||
|
user_profile.save()
|
||||||
|
json_result = dict(
|
||||||
|
api_key = user_profile.api_key
|
||||||
|
)
|
||||||
|
return json_success(json_result)
|
||||||
|
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def regenerate_bot_api_key(request, user_profile, email):
|
def regenerate_bot_api_key(request, user_profile, email):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -174,6 +174,8 @@ v1_api_and_json_patterns = patterns('zerver.views',
|
||||||
{'GET': 'list_subscriptions_backend',
|
{'GET': 'list_subscriptions_backend',
|
||||||
'POST': 'add_subscriptions_backend',
|
'POST': 'add_subscriptions_backend',
|
||||||
'PATCH': 'update_subscriptions_backend'}),
|
'PATCH': 'update_subscriptions_backend'}),
|
||||||
|
url(r'^users/me/api_key/regenerate$', 'rest_dispatch',
|
||||||
|
{'POST': 'regenerate_api_key'}),
|
||||||
url(r'^users/(?P<email>.*)$', 'rest_dispatch',
|
url(r'^users/(?P<email>.*)$', 'rest_dispatch',
|
||||||
{'DELETE': 'deactivate_user_backend'}),
|
{'DELETE': 'deactivate_user_backend'}),
|
||||||
url(r'^bots/(?P<email>.*)/api_key/regenerate$', 'rest_dispatch',
|
url(r'^bots/(?P<email>.*)/api_key/regenerate$', 'rest_dispatch',
|
||||||
|
|
Loading…
Reference in New Issue