Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

do_change_full_name: Noop if value isn't really changing.

Prakhar Pratyushbfe7eb6b2c50
diff --git a/zerver/actions/user_settings.py b/zerver/actions/user_settings.py
index b2ec7a92a3b..2cd71e7a018 100644
--- a/zerver/actions/user_settings.py
+++ b/zerver/actions/user_settings.py
@@ -217,6 +217,9 @@ def do_change_full_name(
user_profile: UserProfile, full_name: str, acting_user: UserProfile | None
) -> None:
old_name = user_profile.full_name
+ if old_name == full_name:
+ return
+
user_profile.full_name = full_name
user_profile.save(update_fields=["full_name"])
event_time = timezone_now()
diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py
index 388acbf8dc5..bf94f90bc85 100644
--- a/zerver/tests/test_events.py
+++ b/zerver/tests/test_events.py
@@ -2079,9 +2079,32 @@ class NormalActionsTest(BaseAction):
)
def test_change_full_name(self) -> None:
+ now = timezone_now()
with self.verify_action() as events:
do_change_full_name(self.user_profile, "Sir Hamlet", self.user_profile)
check_realm_user_update("events[0]", events[0], "full_name")
+ self.assertEqual(
+ RealmAuditLog.objects.filter(
+ realm=self.user_profile.realm,
+ event_type=RealmAuditLog.USER_FULL_NAME_CHANGED,
+ event_time__gte=now,
+ acting_user=self.user_profile,
+ ).count(),
+ 1,
+ )
+
+ # Verify no operation if the value isn't changing.
+ with self.verify_action(num_events=0, state_change_expected=False):
+ do_change_full_name(self.user_profile, "Sir Hamlet", self.user_profile)
+ self.assertEqual(
+ RealmAuditLog.objects.filter(
+ realm=self.user_profile.realm,
+ event_type=RealmAuditLog.USER_FULL_NAME_CHANGED,
+ event_time__gte=now,
+ acting_user=self.user_profile,
+ ).count(),
+ 1,
+ )
self.set_up_db_for_testing_user_access()
cordelia = self.example_user("cordelia")