From 63c157a22b27f3831dc472f9b0b01947f825b425 Mon Sep 17 00:00:00 2001 From: Rafid Aslam Date: Wed, 14 Dec 2016 01:17:49 +0700 Subject: [PATCH] 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. --- zerver/tests/tests.py | 18 ++++++++++++++++++ zerver/views/pointer.py | 8 +++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/zerver/tests/tests.py b/zerver/tests/tests.py index 5ab42099a1..e6bac774ca 100644 --- a/zerver/tests/tests.py +++ b/zerver/tests/tests.py @@ -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 """ diff --git a/zerver/views/pointer.py b/zerver/views/pointer.py index a293f1aaf4..fb6b464dc2 100644 --- a/zerver/views/pointer.py +++ b/zerver/views/pointer.py @@ -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: