models: Add USER_CHANGE_PASSWORD event type constant to RealmAuditLog.

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

View File

@ -2794,7 +2794,7 @@ def do_change_password(user_profile: UserProfile, password: str, commit: bool=Tr
user_profile.save(update_fields=["password"])
event_time = timezone_now()
RealmAuditLog.objects.create(realm=user_profile.realm, acting_user=user_profile,
modified_user=user_profile, event_type='user_change_password',
modified_user=user_profile, event_type=RealmAuditLog.USER_CHANGE_PASSWORD,
event_time=event_time)
def do_change_full_name(user_profile: UserProfile, full_name: str,

View File

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

View File

@ -36,7 +36,7 @@ class TestRealmAuditLog(ZulipTestCase):
user = self.example_user('hamlet')
password = 'test1'
do_change_password(user, password)
self.assertEqual(RealmAuditLog.objects.filter(event_type='user_change_password',
self.assertEqual(RealmAuditLog.objects.filter(event_type=RealmAuditLog.USER_CHANGE_PASSWORD,
event_time__gte=now).count(), 1)
self.assertIsNone(validate_password(password, user))