models: Add USER_EMAIL_CHANGED event type constant to RealmAuditLog.

This commit is contained in:
Vishnu Ks 2018-07-10 09:49:50 +05:30 committed by Tim Abbott
parent 75ed3f92e2
commit 83ff688bb6
3 changed files with 4 additions and 3 deletions

View File

@ -797,7 +797,7 @@ def do_change_user_email(user_profile: UserProfile, new_email: str) -> None:
active_user_ids(user_profile.realm_id)) active_user_ids(user_profile.realm_id))
event_time = timezone_now() event_time = timezone_now()
RealmAuditLog.objects.create(realm=user_profile.realm, acting_user=user_profile, 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) event_time=event_time)
def do_start_email_change_process(user_profile: UserProfile, new_email: str) -> None: def do_start_email_change_process(user_profile: UserProfile, new_email: str) -> None:

View File

@ -1969,6 +1969,7 @@ class RealmAuditLog(models.Model):
USER_CHANGE_PASSWORD = 'user_change_password' USER_CHANGE_PASSWORD = 'user_change_password'
USER_CHANGE_AVATAR_SOURCE = 'user_change_avatar_source' USER_CHANGE_AVATAR_SOURCE = 'user_change_avatar_source'
USER_FULL_NAME_CHANGED = 'user_full_name_changed' USER_FULL_NAME_CHANGED = 'user_full_name_changed'
USER_EMAIL_CHANGED = 'user_email_changed'
event_type = models.CharField(max_length=40) # type: str event_type = models.CharField(max_length=40) # type: str

View File

@ -45,12 +45,12 @@ class TestRealmAuditLog(ZulipTestCase):
user = self.example_user('hamlet') user = self.example_user('hamlet')
email = 'test@example.com' email = 'test@example.com'
do_change_user_email(user, email) 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) event_time__gte=now).count(), 1)
self.assertEqual(email, user.email) self.assertEqual(email, user.email)
# Test the RealmAuditLog stringification # 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("<RealmAuditLog: <UserProfile: test@example.com <Realm: zulip 1>> user_email_changed ")) self.assertTrue(str(audit_entry).startswith("<RealmAuditLog: <UserProfile: test@example.com <Realm: zulip 1>> user_email_changed "))
def test_change_avatar_source(self) -> None: def test_change_avatar_source(self) -> None: