mirror of https://github.com/zulip/zulip.git
API: Expose more information in `get_profile_backend()`
Adding more additional information about user profile to `zerver.views.pointer.get_profile_backend`, like `user_id`, `full_name`, `email`, `is_bot`, `is_admin`, and `short_name` of the user.
This commit is contained in:
parent
988a2e2d8e
commit
63c157a22b
|
@ -1729,6 +1729,24 @@ class GetProfileTest(ZulipTestCase):
|
|||
self.assert_length(cache_queries, 1)
|
||||
self.assertEqual(user_profile.email, 'hamlet@zulip.com')
|
||||
|
||||
def test_get_user_profile(self):
|
||||
# type: () -> None
|
||||
self.login('hamlet@zulip.com')
|
||||
result = ujson.loads(self.client_get('/json/users/me').content)
|
||||
self.assertEqual(result['short_name'], 'hamlet')
|
||||
self.assertEqual(result['email'], 'hamlet@zulip.com')
|
||||
self.assertEqual(result['full_name'], 'King Hamlet')
|
||||
self.assertIn("user_id", result)
|
||||
self.assertFalse(result['is_bot'])
|
||||
self.assertFalse(result['is_admin'])
|
||||
self.login('iago@zulip.com')
|
||||
result = ujson.loads(self.client_get('/json/users/me').content)
|
||||
self.assertEqual(result['short_name'], 'iago')
|
||||
self.assertEqual(result['email'], 'iago@zulip.com')
|
||||
self.assertEqual(result['full_name'], 'Iago')
|
||||
self.assertFalse(result['is_bot'])
|
||||
self.assertTrue(result['is_admin'])
|
||||
|
||||
def test_api_get_empty_profile(self):
|
||||
# type: () -> None
|
||||
"""
|
||||
|
|
|
@ -45,7 +45,13 @@ def get_profile_backend(request, user_profile):
|
|||
# type: (HttpRequest, UserProfile) -> HttpResponse
|
||||
result = dict(pointer = user_profile.pointer,
|
||||
client_id = generate_client_id(),
|
||||
max_message_id = -1)
|
||||
max_message_id = -1,
|
||||
user_id = user_profile.id,
|
||||
full_name = user_profile.full_name,
|
||||
email = user_profile.email,
|
||||
is_bot = user_profile.is_bot,
|
||||
is_admin = user_profile.is_realm_admin,
|
||||
short_name = user_profile.short_name)
|
||||
|
||||
messages = Message.objects.filter(usermessage__user_profile=user_profile).order_by('-id')[:1]
|
||||
if messages:
|
||||
|
|
Loading…
Reference in New Issue