From 7883cecf28cccf4fbed7457c78a19963f72bb559 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Tue, 25 Oct 2016 18:35:32 -0700 Subject: [PATCH] Send user_id to the client in more places. This commit touches: realm_bot/add realm_user/add page_params.bot_list page_params.people_list --- zerver/lib/actions.py | 3 +++ zerver/models.py | 1 + zerver/tests/test_events.py | 1 + zerver/tests/tests.py | 22 ++++++++++++++++++++-- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index dbbdef7a5c..eea0aec583 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -269,6 +269,7 @@ def notify_created_user(user_profile): # type: (UserProfile) -> None event = dict(type="realm_user", op="add", person=dict(email=user_profile.email, + user_id=user_profile.id, is_admin=user_profile.is_realm_admin, full_name=user_profile.full_name, is_bot=user_profile.is_bot)) @@ -288,6 +289,7 @@ def notify_created_bot(user_profile): event = dict(type="realm_bot", op="add", bot=dict(email=user_profile.email, + user_id=user_profile.id, full_name=user_profile.full_name, api_key=user_profile.api_key, default_sending_stream=default_sending_stream_name, @@ -2784,6 +2786,7 @@ def get_status_dict(requesting_user_profile): def get_realm_user_dicts(user_profile): # type: (UserProfile) -> List[Dict[str, text_type]] return [{'email' : userdict['email'], + 'user_id' : userdict['id'], 'is_admin' : userdict['is_realm_admin'], 'is_bot' : userdict['is_bot'], 'full_name' : userdict['full_name']} diff --git a/zerver/models.py b/zerver/models.py index 1366beb991..79760616f5 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -1065,6 +1065,7 @@ def get_owned_bot_dicts(user_profile, include_all_realm_bots_if_admin=True): from zerver.lib.avatar import get_avatar_url return [{'email': botdict['email'], + 'user_id': botdict['id'], 'full_name': botdict['full_name'], 'api_key': botdict['api_key'], 'default_sending_stream': botdict['default_sending_stream__name'], diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py index b962091918..a2b0be2c64 100644 --- a/zerver/tests/test_events.py +++ b/zerver/tests/test_events.py @@ -624,6 +624,7 @@ class EventsRegisterTest(ZulipTestCase): ('op', equals('add')), ('bot', check_dict([ ('email', check_string), + ('user_id', check_int), ('full_name', check_string), ('api_key', check_string), ('default_sending_stream', check_none_or(check_string)), diff --git a/zerver/tests/tests.py b/zerver/tests/tests.py index e15bba2f85..63f6d0e074 100644 --- a/zerver/tests/tests.py +++ b/zerver/tests/tests.py @@ -772,12 +772,15 @@ class BotTest(ZulipTestCase): result = self.create_bot() self.assert_num_bots_equal(1) + bot = get_user_profile_by_email('hambot-bot@zulip.com') + event = [e for e in events if e['event']['type'] == 'realm_bot'][0] self.assertEqual( dict( type='realm_bot', op='add', bot=dict(email='hambot-bot@zulip.com', + user_id=bot.id, full_name='The Bot of Hamlet', api_key=result['api_key'], avatar_url=result['avatar_url'], @@ -931,6 +934,7 @@ class BotTest(ZulipTestCase): type='realm_bot', op='add', bot=dict(email='hambot-bot@zulip.com', + user_id=profile.id, full_name='The Bot of Hamlet', api_key=result['api_key'], avatar_url=result['avatar_url'], @@ -984,8 +988,8 @@ class BotTest(ZulipTestCase): self.assert_num_bots_equal(1) self.assertEqual(result['default_events_register_stream'], 'Denmark') - profile = get_user_profile_by_email('hambot-bot@zulip.com') - self.assertEqual(profile.default_events_register_stream.name, 'Denmark') + bot_profile = get_user_profile_by_email('hambot-bot@zulip.com') + self.assertEqual(bot_profile.default_events_register_stream.name, 'Denmark') event = [e for e in events if e['event']['type'] == 'realm_bot'][0] self.assertEqual( @@ -994,6 +998,7 @@ class BotTest(ZulipTestCase): op='add', bot=dict(email='hambot-bot@zulip.com', full_name='The Bot of Hamlet', + user_id=bot_profile.id, api_key=result['api_key'], avatar_url=result['avatar_url'], default_sending_stream=None, @@ -1962,6 +1967,19 @@ class HomeTest(ZulipTestCase): page_params = self._get_page_params(result) self.assertEqual(page_params['notifications_stream'], 'Denmark') + def test_people(self): + # type: () -> None + email = 'hamlet@zulip.com' + self.login(email) + result = self._get_home_page() + page_params = self._get_page_params(result) + for params in ['people_list', 'bot_list']: + users = page_params['people_list'] + self.assertTrue(len(users) >= 3) + for user in users: + self.assertEqual(user['user_id'], + get_user_profile_by_email(user['email']).id) + def test_new_stream(self): # type: () -> None email = 'hamlet@zulip.com'