mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 21:43:21 +00:00
events: Fix broken custom_profile_fields events logic.
I noticed this because the test_events.py tests had the extremely weird pattern of calling the actual change function, and then testing the `notify` function's state changes (which should always be noops), rather than actually testing the state change function. Fixing the test made it clear that the actual logic in events.py simply did not handle deleting custom_profile_field_value elements from user objects when a custom_profile_field object was deleted. So we fix that bit of logic as well. It appears this bug was unique -- at least we don't have any other notify_* functions being used directly in test_events.py, and the handful of state_change_expected=False entries are all events for data not present in page_params.
This commit is contained in:
@@ -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"]
|
||||
|
||||
@@ -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.name
|
||||
hint = "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:
|
||||
|
||||
Reference in New Issue
Block a user