user_settings: Create RealmAuditLog entries for all user settings.

We previously created RealmAuditLog entries for user notification
settings only. This commit changes the code to create entries for
all user settings. We cannot backfill the entries since we don't
have the data to do that.
This commit is contained in:
Sahil Batra 2023-03-23 18:06:02 +05:30 committed by Tim Abbott
parent 0c46bbdf9f
commit ce562c4820
2 changed files with 27 additions and 25 deletions

View File

@ -415,12 +415,6 @@ def do_change_user_setting(
# TODO: Move these database actions into a transaction.atomic block.
user_profile.save(update_fields=[setting_name])
if setting_name in UserProfile.notification_setting_types:
# Prior to all personal settings being managed by property_types,
# these were only created for notification settings.
#
# TODO: Start creating these for all settings, and do a
# backfilled=True migration.
RealmAuditLog.objects.create(
realm=user_profile.realm,
event_type=RealmAuditLog.USER_SETTING_CHANGED,
@ -435,6 +429,7 @@ def do_change_user_setting(
}
).decode(),
)
# Disabling digest emails should clear a user's email queue
if setting_name == "enable_digest_emails" and not setting_value:
clear_scheduled_emails(user_profile.id, ScheduledEmail.DIGEST)

View File

@ -670,13 +670,20 @@ class TestRealmAuditLog(ZulipTestCase):
)
self.assertEqual(stream.name, "updated name")
def test_change_notification_settings(self) -> None:
def test_change_user_settings(self) -> None:
user = self.example_user("hamlet")
value: Union[bool, int, str]
for setting, v in user.notification_setting_types.items():
if setting == "notification_sound":
value = "ding"
elif setting == "desktop_icon_count_display":
test_values = dict(
default_language="de",
default_view="all_messages",
emojiset="twitter",
notification_sound="ding",
)
for setting, setting_type in user.property_types.items():
if setting in test_values:
value = test_values[setting]
elif setting_type is int:
value = 3
else:
value = False