models: Rename remaining audit log event types to past tense.

This makes the realm audit event type log entries more consistent.
This commit is contained in:
Vishnu Ks 2018-07-22 22:01:13 +05:30 committed by Tim Abbott
parent 28167585b1
commit 2b28042ddf
4 changed files with 35 additions and 9 deletions

View File

@ -2837,7 +2837,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=RealmAuditLog.USER_CHANGE_PASSWORD,
modified_user=user_profile, event_type=RealmAuditLog.USER_PASSWORD_CHANGED,
event_time=event_time)
def do_change_full_name(user_profile: UserProfile, full_name: str,
@ -2875,7 +2875,7 @@ def do_change_bot_owner(user_profile: UserProfile, bot_owner: UserProfile,
user_profile.save() # Can't use update_fields because of how the foreign key works.
event_time = timezone_now()
RealmAuditLog.objects.create(realm=user_profile.realm, acting_user=acting_user,
modified_user=user_profile, event_type=RealmAuditLog.BOT_OWNER_CHANGED,
modified_user=user_profile, event_type=RealmAuditLog.USER_BOT_OWNER_CHANGED,
event_time=event_time)
update_users = bot_owner_user_ids(user_profile)
@ -2942,7 +2942,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=RealmAuditLog.USER_CHANGE_AVATAR_SOURCE,
event_type=RealmAuditLog.USER_AVATAR_SOURCE_CHANGED,
extra_data={'avatar_source': avatar_source},
event_time=event_time)

View File

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from django.apps import apps
from django.db.models import F
from django.db.backends.postgresql_psycopg2.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps
def change_realm_audit_log_event_type_tense(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
RealmAuditLog = apps.get_model('zerver', 'RealmAuditLog')
RealmAuditLog.objects.filter(event_type="user_change_password").update(event_type="user_password_changed")
RealmAuditLog.objects.filter(event_type="user_change_avatar_source").update(event_type="user_avatar_source_changed")
RealmAuditLog.objects.filter(event_type="bot_owner_changed").update(event_type="user_bot_owner_changed")
class Migration(migrations.Migration):
dependencies = [
('zerver', '0174_userprofile_delivery_email'),
]
operations = [
migrations.RunPython(change_realm_audit_log_event_type_tense,
reverse_code=migrations.RunPython.noop),
]

View File

@ -1995,17 +1995,17 @@ class RealmAuditLog(models.Model):
USER_REACTIVATED = 'user_reactivated'
USER_SOFT_ACTIVATED = 'user_soft_activated'
USER_SOFT_DEACTIVATED = 'user_soft_deactivated'
USER_CHANGE_PASSWORD = 'user_change_password'
USER_CHANGE_AVATAR_SOURCE = 'user_change_avatar_source'
USER_PASSWORD_CHANGED = 'user_password_changed'
USER_AVATAR_SOURCE_CHANGED = 'user_avatar_source_changed'
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'
USER_BOT_OWNER_CHANGED = 'user_bot_owner_changed'
REALM_DEACTIVATED = 'realm_deactivated'
REALM_REACTIVATED = 'realm_reactivated'
BOT_OWNER_CHANGED = 'bot_owner_changed'
SUBSCRIPTION_CREATED = 'subscription_created'
SUBSCRIPTION_ACTIVATED = 'subscription_activated'
SUBSCRIPTION_DEACTIVATED = 'subscription_deactivated'

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=RealmAuditLog.USER_CHANGE_PASSWORD,
self.assertEqual(RealmAuditLog.objects.filter(event_type=RealmAuditLog.USER_PASSWORD_CHANGED,
event_time__gte=now).count(), 1)
self.assertIsNone(validate_password(password, user))
@ -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=RealmAuditLog.USER_CHANGE_AVATAR_SOURCE,
self.assertEqual(RealmAuditLog.objects.filter(event_type=RealmAuditLog.USER_AVATAR_SOURCE_CHANGED,
event_time__gte=now).count(), 1)
self.assertEqual(avatar_source, user.avatar_source)
@ -88,7 +88,7 @@ class TestRealmAuditLog(ZulipTestCase):
bot = self.notification_bot()
bot_owner = self.example_user('hamlet')
do_change_bot_owner(bot, bot_owner, admin)
self.assertEqual(RealmAuditLog.objects.filter(event_type=RealmAuditLog.BOT_OWNER_CHANGED,
self.assertEqual(RealmAuditLog.objects.filter(event_type=RealmAuditLog.USER_BOT_OWNER_CHANGED,
event_time__gte=now).count(), 1)
self.assertEqual(bot_owner, bot.bot_owner)