models: Add BOT_OWNER_CHANGED event type constant to RealmAuditLog.

This commit is contained in:
Vishnu Ks
2018-07-10 10:18:15 +05:30
committed by Tim Abbott
parent 9670e319cc
commit 20fae065f6
3 changed files with 4 additions and 2 deletions

View File

@@ -2832,7 +2832,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. user_profile.save() # Can't use update_fields because of how the foreign key works.
event_time = timezone_now() event_time = timezone_now()
RealmAuditLog.objects.create(realm=user_profile.realm, acting_user=acting_user, RealmAuditLog.objects.create(realm=user_profile.realm, acting_user=acting_user,
modified_user=user_profile, event_type='bot_owner_changed', modified_user=user_profile, event_type=RealmAuditLog.BOT_OWNER_CHANGED,
event_time=event_time) event_time=event_time)
update_users = bot_owner_user_ids(user_profile) update_users = bot_owner_user_ids(user_profile)

View File

@@ -1976,6 +1976,8 @@ class RealmAuditLog(models.Model):
REALM_DEACTIVATED = 'realm_deactivated' REALM_DEACTIVATED = 'realm_deactivated'
REALM_REACTIVATED = 'realm_reactivated' REALM_REACTIVATED = 'realm_reactivated'
BOT_OWNER_CHANGED = 'bot_owner_changed'
event_type = models.CharField(max_length=40) # type: str event_type = models.CharField(max_length=40) # type: str
def __str__(self) -> str: def __str__(self) -> str:

View File

@@ -88,7 +88,7 @@ class TestRealmAuditLog(ZulipTestCase):
bot = self.notification_bot() bot = self.notification_bot()
bot_owner = self.example_user('hamlet') bot_owner = self.example_user('hamlet')
do_change_bot_owner(bot, bot_owner, admin) do_change_bot_owner(bot, bot_owner, admin)
self.assertEqual(RealmAuditLog.objects.filter(event_type='bot_owner_changed', self.assertEqual(RealmAuditLog.objects.filter(event_type=RealmAuditLog.BOT_OWNER_CHANGED,
event_time__gte=now).count(), 1) event_time__gte=now).count(), 1)
self.assertEqual(bot_owner, bot.bot_owner) self.assertEqual(bot_owner, bot.bot_owner)