Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
events: Fix broken custom_profile_fields events logic.
Tim Abbott96c61a1a41ec
diff --git a/zerver/lib/events.py b/zerver/lib/events.pyindex a9981ff2198..23f2a385869 100644--- a/zerver/lib/events.py+++ b/zerver/lib/events.py@@ -530,6 +530,16 @@ def apply_event(state["hotspots"] = event["hotspots"]elif event["type"] == "custom_profile_fields":state["custom_profile_fields"] = event["fields"]+ custom_profile_field_ids = {field["id"] for field in state["custom_profile_fields"]}++ if "raw_users" in state:+ for user_dict in state["raw_users"].values():+ if "profile_data" not in user_dict:+ continue+ profile_data = user_dict["profile_data"]+ for (field_id, field_data) in list(profile_data.items()):+ if int(field_id) not in custom_profile_field_ids:+ del profile_data[field_id]elif event["type"] == "realm_user":person = event["person"]person_user_id = person["user_id"]diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.pyindex 757776d8855..8ad4cd81ef0 100644--- a/zerver/tests/test_events.py+++ b/zerver/tests/test_events.py@@ -91,7 +91,6 @@ from zerver.lib.actions import (do_update_user_presence,do_update_user_status,lookup_default_stream_groups,- notify_realm_custom_profile_fields,remove_members_from_user_group,try_add_realm_custom_profile_field,try_update_realm_custom_profile_field,@@ -698,33 +697,24 @@ class NormalActionsTest(BaseAction):def test_custom_profile_fields_events(self) -> None:realm = self.user_profile.realm- try_add_realm_custom_profile_field(- realm=realm, name="Expertise", field_type=CustomProfileField.LONG_TEXT- )events = self.verify_action(- lambda: notify_realm_custom_profile_fields(self.user_profile.realm),- state_change_expected=False,+ lambda: try_add_realm_custom_profile_field(+ realm=realm, name="Expertise", field_type=CustomProfileField.LONG_TEXT+ ))check_custom_profile_fields("events[0]", events[0])field = realm.customprofilefield_set.get(realm=realm, name="Biography")name = field.namehint = "Biography of the user"- try_update_realm_custom_profile_field(realm, field, name, hint=hint)events = self.verify_action(- lambda: notify_realm_custom_profile_fields(self.user_profile.realm),- state_change_expected=False,+ lambda: try_update_realm_custom_profile_field(realm, field, name, hint=hint))check_custom_profile_fields("events[0]", events[0])- do_remove_realm_custom_profile_field(realm, field)-- events = self.verify_action(- lambda: notify_realm_custom_profile_fields(self.user_profile.realm),- state_change_expected=False,- )+ events = self.verify_action(lambda: do_remove_realm_custom_profile_field(realm, field))check_custom_profile_fields("events[0]", events[0])def test_custom_profile_field_data_events(self) -> None: