models: Add USER_CHANGE_AVATAR_SOURCE event type constant to RealmAuditLog.

This commit is contained in:
Vishnu Ks 2018-07-09 23:49:31 +05:30 committed by Tim Abbott
parent 4c73221108
commit c8aac0fbb9
3 changed files with 3 additions and 2 deletions

View File

@ -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"]) user_profile.save(update_fields=["avatar_source", "avatar_version"])
event_time = timezone_now() event_time = timezone_now()
RealmAuditLog.objects.create(realm=user_profile.realm, modified_user=user_profile, 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}, extra_data={'avatar_source': avatar_source},
event_time=event_time) event_time=event_time)

View File

@ -1967,6 +1967,7 @@ class RealmAuditLog(models.Model):
USER_DEACTIVATED = 'user_deactivated' USER_DEACTIVATED = 'user_deactivated'
USER_REACTIVATED = 'user_reactivated' USER_REACTIVATED = 'user_reactivated'
USER_CHANGE_PASSWORD = 'user_change_password' USER_CHANGE_PASSWORD = 'user_change_password'
USER_CHANGE_AVATAR_SOURCE = 'user_change_avatar_source'
event_type = models.CharField(max_length=40) # type: str event_type = models.CharField(max_length=40) # type: str

View File

@ -58,7 +58,7 @@ class TestRealmAuditLog(ZulipTestCase):
user = self.example_user('hamlet') user = self.example_user('hamlet')
avatar_source = u'G' avatar_source = u'G'
do_change_avatar_fields(user, avatar_source) 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) event_time__gte=now).count(), 1)
self.assertEqual(avatar_source, user.avatar_source) self.assertEqual(avatar_source, user.avatar_source)