diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index a4d3d2cbc9..76be4da5f1 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -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, diff --git a/zerver/models.py b/zerver/models.py index 3577dd6803..27dcc6feef 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -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 diff --git a/zerver/tests/test_audit_log.py b/zerver/tests/test_audit_log.py index 6297376faf..fea7fd04a8 100644 --- a/zerver/tests/test_audit_log.py +++ b/zerver/tests/test_audit_log.py @@ -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))