mirror of https://github.com/zulip/zulip.git
do_set_realm_property: Noop if value isn't really changing.
It makes no sense to do operations if the value isn't changing. In particular, this creates RealmAuditLog entries and sends useless events.
This commit is contained in:
parent
cf68f8ae24
commit
b09f3a2da1
|
@ -56,6 +56,9 @@ def do_set_realm_property(
|
|||
), f"Cannot update {name}: {value} is not an instance of {property_type}"
|
||||
|
||||
old_value = getattr(realm, name)
|
||||
if old_value == value:
|
||||
return
|
||||
|
||||
setattr(realm, name, value)
|
||||
realm.save(update_fields=[name])
|
||||
|
||||
|
|
|
@ -3532,16 +3532,20 @@ class RealmPropertyActionTest(BaseAction):
|
|||
if vals is None:
|
||||
raise AssertionError(f"No test created for {name}")
|
||||
now = timezone_now()
|
||||
original_val = getattr(self.user_profile.realm, name)
|
||||
|
||||
do_set_realm_property(self.user_profile.realm, name, vals[0], acting_user=self.user_profile)
|
||||
self.assertEqual(
|
||||
RealmAuditLog.objects.filter(
|
||||
realm=self.user_profile.realm,
|
||||
event_type=RealmAuditLog.REALM_PROPERTY_CHANGED,
|
||||
event_time__gte=now,
|
||||
acting_user=self.user_profile,
|
||||
).count(),
|
||||
1,
|
||||
)
|
||||
|
||||
if vals[0] != original_val:
|
||||
self.assertEqual(
|
||||
RealmAuditLog.objects.filter(
|
||||
realm=self.user_profile.realm,
|
||||
event_type=RealmAuditLog.REALM_PROPERTY_CHANGED,
|
||||
event_time__gte=now,
|
||||
acting_user=self.user_profile,
|
||||
).count(),
|
||||
1,
|
||||
)
|
||||
for count, val in enumerate(vals[1:]):
|
||||
now = timezone_now()
|
||||
state_change_expected = True
|
||||
|
|
Loading…
Reference in New Issue