From c8aac0fbb9503853550a847a03e6411146b8309f Mon Sep 17 00:00:00 2001 From: Vishnu Ks Date: Mon, 9 Jul 2018 23:49:31 +0530 Subject: [PATCH] models: Add USER_CHANGE_AVATAR_SOURCE event type constant to RealmAuditLog. --- zerver/lib/actions.py | 2 +- zerver/models.py | 1 + zerver/tests/test_audit_log.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 76be4da5f1..03a59aa9c4 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -2898,7 +2898,7 @@ def do_change_avatar_fields(user_profile: UserProfile, avatar_source: str) -> No user_profile.save(update_fields=["avatar_source", "avatar_version"]) event_time = timezone_now() RealmAuditLog.objects.create(realm=user_profile.realm, modified_user=user_profile, - event_type='user_change_avatar_source', + event_type=RealmAuditLog.USER_CHANGE_AVATAR_SOURCE, extra_data={'avatar_source': avatar_source}, event_time=event_time) diff --git a/zerver/models.py b/zerver/models.py index 27dcc6feef..b43aa1c830 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -1967,6 +1967,7 @@ class RealmAuditLog(models.Model): USER_DEACTIVATED = 'user_deactivated' USER_REACTIVATED = 'user_reactivated' USER_CHANGE_PASSWORD = 'user_change_password' + USER_CHANGE_AVATAR_SOURCE = 'user_change_avatar_source' 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 fea7fd04a8..526d28348d 100644 --- a/zerver/tests/test_audit_log.py +++ b/zerver/tests/test_audit_log.py @@ -58,7 +58,7 @@ class TestRealmAuditLog(ZulipTestCase): user = self.example_user('hamlet') avatar_source = u'G' do_change_avatar_fields(user, avatar_source) - self.assertEqual(RealmAuditLog.objects.filter(event_type='user_change_avatar_source', + self.assertEqual(RealmAuditLog.objects.filter(event_type=RealmAuditLog.USER_CHANGE_AVATAR_SOURCE, event_time__gte=now).count(), 1) self.assertEqual(avatar_source, user.avatar_source)