models: Add USER_API_KEY_CHANGED event type constant to RealmAuditLog.

This commit is contained in:
Vishnu Ks 2018-07-10 09:59:08 +05:30 committed by Tim Abbott
parent 0d69fc482b
commit d5b6f032d2
3 changed files with 3 additions and 2 deletions

View File

@ -2881,7 +2881,7 @@ def do_regenerate_api_key(user_profile: UserProfile, acting_user: UserProfile) -
user_profile.save(update_fields=["api_key"])
event_time = timezone_now()
RealmAuditLog.objects.create(realm=user_profile.realm, acting_user=acting_user,
modified_user=user_profile, event_type='user_api_key_changed',
modified_user=user_profile, event_type=RealmAuditLog.USER_API_KEY_CHANGED,
event_time=event_time)
if user_profile.is_bot:

View File

@ -1971,6 +1971,7 @@ class RealmAuditLog(models.Model):
USER_FULL_NAME_CHANGED = 'user_full_name_changed'
USER_EMAIL_CHANGED = 'user_email_changed'
USER_TOS_VERSION_CHANGED = 'user_tos_version_changed'
USER_API_KEY_CHANGED = 'user_api_key_changed'
event_type = models.CharField(max_length=40) # type: str

View File

@ -96,7 +96,7 @@ class TestRealmAuditLog(ZulipTestCase):
now = timezone_now()
user = self.example_user('hamlet')
do_regenerate_api_key(user, user)
self.assertEqual(RealmAuditLog.objects.filter(event_type='user_api_key_changed',
self.assertEqual(RealmAuditLog.objects.filter(event_type=RealmAuditLog.USER_API_KEY_CHANGED,
event_time__gte=now).count(), 1)
self.assertTrue(user.api_key)