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,26 +415,21 @@ def do_change_user_setting(
# TODO: Move these database actions into a transaction.atomic block. # TODO: Move these database actions into a transaction.atomic block.
user_profile.save(update_fields=[setting_name]) user_profile.save(update_fields=[setting_name])
if setting_name in UserProfile.notification_setting_types: RealmAuditLog.objects.create(
# Prior to all personal settings being managed by property_types, realm=user_profile.realm,
# these were only created for notification settings. event_type=RealmAuditLog.USER_SETTING_CHANGED,
# event_time=event_time,
# TODO: Start creating these for all settings, and do a acting_user=acting_user,
# backfilled=True migration. modified_user=user_profile,
RealmAuditLog.objects.create( extra_data=orjson.dumps(
realm=user_profile.realm, {
event_type=RealmAuditLog.USER_SETTING_CHANGED, RealmAuditLog.OLD_VALUE: old_value,
event_time=event_time, RealmAuditLog.NEW_VALUE: setting_value,
acting_user=acting_user, "property": setting_name,
modified_user=user_profile, }
extra_data=orjson.dumps( ).decode(),
{ )
RealmAuditLog.OLD_VALUE: old_value,
RealmAuditLog.NEW_VALUE: setting_value,
"property": setting_name,
}
).decode(),
)
# Disabling digest emails should clear a user's email queue # Disabling digest emails should clear a user's email queue
if setting_name == "enable_digest_emails" and not setting_value: if setting_name == "enable_digest_emails" and not setting_value:
clear_scheduled_emails(user_profile.id, ScheduledEmail.DIGEST) clear_scheduled_emails(user_profile.id, ScheduledEmail.DIGEST)

View File

@ -670,13 +670,20 @@ class TestRealmAuditLog(ZulipTestCase):
) )
self.assertEqual(stream.name, "updated name") 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") user = self.example_user("hamlet")
value: Union[bool, int, str] value: Union[bool, int, str]
for setting, v in user.notification_setting_types.items(): test_values = dict(
if setting == "notification_sound": default_language="de",
value = "ding" default_view="all_messages",
elif setting == "desktop_icon_count_display": 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 value = 3
else: else:
value = False value = False