events: Only send bot_type for bots and thus remove the for_api param.

This commit is contained in:
Hemanth V. Alluri 2019-10-26 22:02:21 +05:30 committed by Tim Abbott
parent fa6bd42f4c
commit c1370547d5
4 changed files with 7 additions and 12 deletions

View File

@ -447,8 +447,10 @@ def notify_created_user(user_profile: UserProfile) -> None:
date_joined=user_profile.date_joined.isoformat(), date_joined=user_profile.date_joined.isoformat(),
is_guest=user_profile.is_guest, is_guest=user_profile.is_guest,
is_bot=user_profile.is_bot) # type: Dict[str, Any] is_bot=user_profile.is_bot) # type: Dict[str, Any]
if user_profile.is_bot and user_profile.bot_owner_id is not None: if user_profile.is_bot:
person["bot_owner_id"] = user_profile.bot_owner_id person["bot_type"] = user_profile.bot_type
if user_profile.bot_owner_id is not None:
person["bot_owner_id"] = user_profile.bot_owner_id
event = dict(type="realm_user", op="add", person=person) # type: Dict[str, Any] event = dict(type="realm_user", op="add", person=person) # type: Dict[str, Any]
if not user_profile.is_bot: if not user_profile.is_bot:
event["person"]["profile_data"] = {} event["person"]["profile_data"] = {}

View File

@ -75,8 +75,7 @@ def get_custom_profile_field_values(realm_id: int) -> Dict[int, Dict[str, Any]]:
return profiles_by_user_id return profiles_by_user_id
def get_raw_user_data(realm: Realm, user_profile: UserProfile, def get_raw_user_data(realm: Realm, user_profile: UserProfile, client_gravatar: bool,
client_gravatar: bool, for_api: bool=False,
include_custom_profile_fields: bool=True) -> Dict[int, Dict[str, str]]: include_custom_profile_fields: bool=True) -> Dict[int, Dict[str, str]]:
user_dicts = get_realm_user_dicts(realm.id) user_dicts = get_realm_user_dicts(realm.id)
@ -115,12 +114,8 @@ def get_raw_user_data(realm: Realm, user_profile: UserProfile,
user_profile.is_realm_admin): user_profile.is_realm_admin):
result['delivery_email'] = row['delivery_email'] result['delivery_email'] = row['delivery_email']
if for_api:
# The API currently has a quirk that it expects to include
# a bot_type field even for human users; this field is
# invalid so we plan to eventually remove this.
result['bot_type'] = row['bot_type']
if is_bot: if is_bot:
result["bot_type"] = row["bot_type"]
if row['email'] in settings.CROSS_REALM_BOT_EMAILS: if row['email'] in settings.CROSS_REALM_BOT_EMAILS:
result['is_cross_realm_bot'] = True result['is_cross_realm_bot'] = True
elif row['bot_owner_id'] is not None: elif row['bot_owner_id'] is not None:

View File

@ -664,9 +664,8 @@ class ListCustomProfileFieldTest(CustomProfileFieldTestCase):
expected_keys_for_iago = { expected_keys_for_iago = {
"email", "user_id", "avatar_url", "is_admin", "is_guest", "is_bot", "email", "user_id", "avatar_url", "is_admin", "is_guest", "is_bot",
"full_name", "timezone", "is_active", "date_joined", "bot_type", "profile_data"} "full_name", "timezone", "is_active", "date_joined", "profile_data"}
self.assertEqual(set(iago_raw_data.keys()), expected_keys_for_iago) self.assertEqual(set(iago_raw_data.keys()), expected_keys_for_iago)
self.assertIsNone(iago_raw_data["bot_type"]) # the key should exist though
self.assertNotEqual(iago_raw_data["profile_data"], {}) self.assertNotEqual(iago_raw_data["profile_data"], {})
expected_keys_for_test_bot = { expected_keys_for_test_bot = {

View File

@ -417,7 +417,6 @@ def get_members_backend(request: HttpRequest, user_profile: UserProfile,
members = get_raw_user_data(realm, members = get_raw_user_data(realm,
user_profile=user_profile, user_profile=user_profile,
client_gravatar=client_gravatar, client_gravatar=client_gravatar,
for_api=True,
include_custom_profile_fields=include_custom_profile_fields) include_custom_profile_fields=include_custom_profile_fields)
return json_success({'members': members.values()}) return json_success({'members': members.values()})