From 83ff688bb6943910e3a2e87bf02b2f01ac0bdcb0 Mon Sep 17 00:00:00 2001 From: Vishnu Ks Date: Tue, 10 Jul 2018 09:49:50 +0530 Subject: [PATCH] models: Add USER_EMAIL_CHANGED event type constant to RealmAuditLog. --- zerver/lib/actions.py | 2 +- zerver/models.py | 1 + zerver/tests/test_audit_log.py | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index f3161a094f..11a65e8697 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -797,7 +797,7 @@ def do_change_user_email(user_profile: UserProfile, new_email: str) -> None: active_user_ids(user_profile.realm_id)) event_time = timezone_now() RealmAuditLog.objects.create(realm=user_profile.realm, acting_user=user_profile, - modified_user=user_profile, event_type='user_email_changed', + modified_user=user_profile, event_type=RealmAuditLog.USER_EMAIL_CHANGED, event_time=event_time) def do_start_email_change_process(user_profile: UserProfile, new_email: str) -> None: diff --git a/zerver/models.py b/zerver/models.py index c9a52b148d..c19897a122 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -1969,6 +1969,7 @@ class RealmAuditLog(models.Model): USER_CHANGE_PASSWORD = 'user_change_password' USER_CHANGE_AVATAR_SOURCE = 'user_change_avatar_source' USER_FULL_NAME_CHANGED = 'user_full_name_changed' + USER_EMAIL_CHANGED = 'user_email_changed' event_type = models.CharField(max_length=40) # type: str diff --git a/zerver/tests/test_audit_log.py b/zerver/tests/test_audit_log.py index 6e0954976f..4a5b01a5a4 100644 --- a/zerver/tests/test_audit_log.py +++ b/zerver/tests/test_audit_log.py @@ -45,12 +45,12 @@ class TestRealmAuditLog(ZulipTestCase): user = self.example_user('hamlet') email = 'test@example.com' do_change_user_email(user, email) - self.assertEqual(RealmAuditLog.objects.filter(event_type='user_email_changed', + self.assertEqual(RealmAuditLog.objects.filter(event_type=RealmAuditLog.USER_EMAIL_CHANGED, event_time__gte=now).count(), 1) self.assertEqual(email, user.email) # Test the RealmAuditLog stringification - audit_entry = RealmAuditLog.objects.get(event_type='user_email_changed', event_time__gte=now) + audit_entry = RealmAuditLog.objects.get(event_type=RealmAuditLog.USER_EMAIL_CHANGED, event_time__gte=now) self.assertTrue(str(audit_entry).startswith("> user_email_changed ")) def test_change_avatar_source(self) -> None: