From 56c8cbde1ee39bf4d85bc33b26d3c8231e212763 Mon Sep 17 00:00:00 2001 From: Lauryn Menard Date: Tue, 3 Sep 2024 16:46:18 +0200 Subject: [PATCH] audit-log: Move realm event types to AuditLogEventType enum. Event types moved: REALM_CREATED, REALM_DEFAULT_USER_SETTINGS_CHANGED REALM_ORG_TYPE_CHANGED, REALM_DOMAIN_ADDED, REALM_DOMAIN_CHANGED REALM_DOMAIN_REMOVED, REALM_PLAYGROUND_ADDED, REALM_PLAYGROUND_REMOVED REALM_LINKIFIER_ADDED, REALM_LINKIFIER_CHANGED, REALM_LINKIFIER_REMOVED REALM_EMOJI_ADDED, REALM_EMOJI_REMOVED, REALM_LINKIFIERS_REORDERED REALM_IMPORTED --- corporate/views/installation_activity.py | 4 +-- zerver/actions/create_realm.py | 2 +- zerver/actions/create_user.py | 4 ++- zerver/actions/realm_domains.py | 7 ++--- zerver/actions/realm_emoji.py | 5 ++-- zerver/actions/realm_linkifiers.py | 9 ++++--- zerver/actions/realm_playgrounds.py | 5 ++-- zerver/actions/realm_settings.py | 4 +-- zerver/lib/import_realm.py | 6 ++--- zerver/lib/server_initialization.py | 3 ++- zerver/models/realm_audit_logs.py | 33 ++++++++++++------------ zerver/tests/test_audit_log.py | 20 +++++++------- zerver/tests/test_events.py | 4 +-- zerver/tests/test_import_export.py | 2 +- zerver/tests/test_realm.py | 10 ++++--- zerver/tests/test_realm_linkifiers.py | 5 ++-- zerver/tests/test_signup.py | 3 ++- zerver/tests/test_slack_importer.py | 4 +-- 18 files changed, 71 insertions(+), 59 deletions(-) diff --git a/corporate/views/installation_activity.py b/corporate/views/installation_activity.py index b96bc97cbb..858e40e5d4 100644 --- a/corporate/views/installation_activity.py +++ b/corporate/views/installation_activity.py @@ -28,7 +28,7 @@ from corporate.views.support import get_plan_type_string from zerver.decorator import require_server_admin from zerver.lib.typed_endpoint import typed_endpoint_without_parameters from zerver.models import Realm -from zerver.models.realm_audit_logs import RealmAuditLog +from zerver.models.realm_audit_logs import AuditLogEventType from zerver.models.realms import get_org_type_display_name @@ -187,7 +187,7 @@ def realm_summary_table() -> str: "active_users_audit_end_time": COUNT_STATS[ "active_users_audit:is_bot:day" ].last_successful_fill(), - "realm_creation_event_type": RealmAuditLog.REALM_CREATED, + "realm_creation_event_type": AuditLogEventType.REALM_CREATED, }, ) rows = dictfetchall(cursor) diff --git a/zerver/actions/create_realm.py b/zerver/actions/create_realm.py index 8ee283dd26..bffa7458a2 100644 --- a/zerver/actions/create_realm.py +++ b/zerver/actions/create_realm.py @@ -270,7 +270,7 @@ def do_create_realm( # do_create_user(..., realm_creation=True). acting_user=None, realm=realm, - event_type=RealmAuditLog.REALM_CREATED, + event_type=AuditLogEventType.REALM_CREATED, event_time=realm.date_created, extra_data={ "how_realm_creator_found_zulip": how_realm_creator_found_zulip, diff --git a/zerver/actions/create_user.py b/zerver/actions/create_user.py index 446f4436cf..5160f74ba3 100644 --- a/zerver/actions/create_user.py +++ b/zerver/actions/create_user.py @@ -552,7 +552,9 @@ def do_create_user( # If this user just created a realm, make sure they are # properly tagged as the creator of the realm. realm_creation_audit_log = ( - RealmAuditLog.objects.filter(event_type=RealmAuditLog.REALM_CREATED, realm=realm) + RealmAuditLog.objects.filter( + event_type=AuditLogEventType.REALM_CREATED, realm=realm + ) .order_by("id") .last() ) diff --git a/zerver/actions/realm_domains.py b/zerver/actions/realm_domains.py index 376bebd173..e5504d3a95 100644 --- a/zerver/actions/realm_domains.py +++ b/zerver/actions/realm_domains.py @@ -3,6 +3,7 @@ from django.utils.timezone import now as timezone_now from zerver.actions.realm_settings import do_set_realm_property from zerver.models import Realm, RealmAuditLog, RealmDomain, UserProfile +from zerver.models.realm_audit_logs import AuditLogEventType from zerver.models.realms import RealmDomainDict, get_realm_domains from zerver.models.users import active_user_ids from zerver.tornado.django_api import send_event_on_commit @@ -20,7 +21,7 @@ def do_add_realm_domain( RealmAuditLog.objects.create( realm=realm, acting_user=acting_user, - event_type=RealmAuditLog.REALM_DOMAIN_ADDED, + event_type=AuditLogEventType.REALM_DOMAIN_ADDED, event_time=timezone_now(), extra_data={ "realm_domains": get_realm_domains(realm), @@ -54,7 +55,7 @@ def do_change_realm_domain( RealmAuditLog.objects.create( realm=realm_domain.realm, acting_user=acting_user, - event_type=RealmAuditLog.REALM_DOMAIN_CHANGED, + event_type=AuditLogEventType.REALM_DOMAIN_CHANGED, event_time=timezone_now(), extra_data={ "realm_domains": get_realm_domains(realm_domain.realm), @@ -85,7 +86,7 @@ def do_remove_realm_domain(realm_domain: RealmDomain, *, acting_user: UserProfil RealmAuditLog.objects.create( realm=realm, acting_user=acting_user, - event_type=RealmAuditLog.REALM_DOMAIN_REMOVED, + event_type=AuditLogEventType.REALM_DOMAIN_REMOVED, event_time=timezone_now(), extra_data={ "realm_domains": get_realm_domains(realm), diff --git a/zerver/actions/realm_emoji.py b/zerver/actions/realm_emoji.py index e81d36a65d..f165d37383 100644 --- a/zerver/actions/realm_emoji.py +++ b/zerver/actions/realm_emoji.py @@ -12,6 +12,7 @@ from zerver.lib.thumbnail import THUMBNAIL_ACCEPT_IMAGE_TYPES, BadImageError from zerver.lib.upload import upload_emoji_image from zerver.lib.upload.base import INLINE_MIME_TYPES from zerver.models import Realm, RealmAuditLog, RealmEmoji, UserProfile +from zerver.models.realm_audit_logs import AuditLogEventType from zerver.models.realm_emoji import EmojiInfo, get_all_custom_emoji_for_realm from zerver.models.users import active_user_ids from zerver.tornado.django_api import send_event_on_commit @@ -54,7 +55,7 @@ def check_add_realm_emoji( RealmAuditLog.objects.create( realm=realm, acting_user=author, - event_type=RealmAuditLog.REALM_EMOJI_ADDED, + event_type=AuditLogEventType.REALM_EMOJI_ADDED, event_time=timezone_now(), extra_data={ "realm_emoji": dict(sorted(realm_emoji_dict.items())), @@ -75,7 +76,7 @@ def do_remove_realm_emoji(realm: Realm, name: str, *, acting_user: UserProfile | RealmAuditLog.objects.create( realm=realm, acting_user=acting_user, - event_type=RealmAuditLog.REALM_EMOJI_REMOVED, + event_type=AuditLogEventType.REALM_EMOJI_REMOVED, event_time=timezone_now(), extra_data={ "realm_emoji": dict(sorted(realm_emoji_dict.items())), diff --git a/zerver/actions/realm_linkifiers.py b/zerver/actions/realm_linkifiers.py index 8928c0c750..ebfb184c9b 100644 --- a/zerver/actions/realm_linkifiers.py +++ b/zerver/actions/realm_linkifiers.py @@ -7,6 +7,7 @@ from zerver.lib.exceptions import JsonableError from zerver.lib.types import LinkifierDict from zerver.models import Realm, RealmAuditLog, RealmFilter, UserProfile from zerver.models.linkifiers import flush_linkifiers, linkifiers_for_realm +from zerver.models.realm_audit_logs import AuditLogEventType from zerver.models.users import active_user_ids from zerver.tornado.django_api import send_event_on_commit @@ -46,7 +47,7 @@ def do_add_linkifier( RealmAuditLog.objects.create( realm=realm, acting_user=acting_user, - event_type=RealmAuditLog.REALM_LINKIFIER_ADDED, + event_type=AuditLogEventType.REALM_LINKIFIER_ADDED, event_time=timezone_now(), extra_data={ "realm_linkifiers": realm_linkifiers, @@ -84,7 +85,7 @@ def do_remove_linkifier( RealmAuditLog.objects.create( realm=realm, acting_user=acting_user, - event_type=RealmAuditLog.REALM_LINKIFIER_REMOVED, + event_type=AuditLogEventType.REALM_LINKIFIER_REMOVED, event_time=timezone_now(), extra_data={ "realm_linkifiers": realm_linkifiers, @@ -118,7 +119,7 @@ def do_update_linkifier( RealmAuditLog.objects.create( realm=realm, acting_user=acting_user, - event_type=RealmAuditLog.REALM_LINKIFIER_CHANGED, + event_type=AuditLogEventType.REALM_LINKIFIER_CHANGED, event_time=timezone_now(), extra_data={ "realm_linkifiers": realm_linkifiers, @@ -173,7 +174,7 @@ def check_reorder_linkifiers( RealmAuditLog.objects.create( realm=realm, acting_user=acting_user, - event_type=RealmAuditLog.REALM_LINKIFIERS_REORDERED, + event_type=AuditLogEventType.REALM_LINKIFIERS_REORDERED, event_time=timezone_now(), extra_data={ "realm_linkifiers": realm_linkifiers, diff --git a/zerver/actions/realm_playgrounds.py b/zerver/actions/realm_playgrounds.py index dee7bc447d..df9731194f 100644 --- a/zerver/actions/realm_playgrounds.py +++ b/zerver/actions/realm_playgrounds.py @@ -5,6 +5,7 @@ from django.utils.timezone import now as timezone_now from zerver.lib.exceptions import ValidationFailureError from zerver.lib.types import RealmPlaygroundDict from zerver.models import Realm, RealmAuditLog, RealmPlayground, UserProfile +from zerver.models.realm_audit_logs import AuditLogEventType from zerver.models.realm_playgrounds import get_realm_playgrounds from zerver.models.users import active_user_ids from zerver.tornado.django_api import send_event_on_commit @@ -43,7 +44,7 @@ def check_add_realm_playground( RealmAuditLog.objects.create( realm=realm, acting_user=acting_user, - event_type=RealmAuditLog.REALM_PLAYGROUND_ADDED, + event_type=AuditLogEventType.REALM_PLAYGROUND_ADDED, event_time=timezone_now(), extra_data={ "realm_playgrounds": realm_playgrounds, @@ -75,7 +76,7 @@ def do_remove_realm_playground( RealmAuditLog.objects.create( realm=realm, acting_user=acting_user, - event_type=RealmAuditLog.REALM_PLAYGROUND_REMOVED, + event_type=AuditLogEventType.REALM_PLAYGROUND_REMOVED, event_time=timezone_now(), extra_data={ "realm_playgrounds": realm_playgrounds, diff --git a/zerver/actions/realm_settings.py b/zerver/actions/realm_settings.py index f09f63d7d3..4962f6378c 100644 --- a/zerver/actions/realm_settings.py +++ b/zerver/actions/realm_settings.py @@ -470,7 +470,7 @@ def do_set_realm_user_default_setting( RealmAuditLog.objects.create( realm=realm, - event_type=RealmAuditLog.REALM_DEFAULT_USER_SETTINGS_CHANGED, + event_type=AuditLogEventType.REALM_DEFAULT_USER_SETTINGS_CHANGED, event_time=event_time, acting_user=acting_user, extra_data={ @@ -687,7 +687,7 @@ def do_change_realm_org_type( realm.save(update_fields=["org_type"]) RealmAuditLog.objects.create( - event_type=RealmAuditLog.REALM_ORG_TYPE_CHANGED, + event_type=AuditLogEventType.REALM_ORG_TYPE_CHANGED, realm=realm, event_time=timezone_now(), acting_user=acting_user, diff --git a/zerver/lib/import_realm.py b/zerver/lib/import_realm.py index 7605fa164f..cfa4fd92c7 100644 --- a/zerver/lib/import_realm.py +++ b/zerver/lib/import_realm.py @@ -1390,11 +1390,11 @@ def do_import_realm(import_dir: Path, subdomain: str, processes: int = 1) -> Rea # log event, even if the export was generated by an export tool # that does not create RealmAuditLog events. if not RealmAuditLog.objects.filter( - realm=realm, event_type=RealmAuditLog.REALM_CREATED + realm=realm, event_type=AuditLogEventType.REALM_CREATED ).exists(): RealmAuditLog.objects.create( realm=realm, - event_type=RealmAuditLog.REALM_CREATED, + event_type=AuditLogEventType.REALM_CREATED, event_time=realm.date_created, # Mark these as backfilled, since they weren't created # when the realm was actually created, and thus do not @@ -1669,7 +1669,7 @@ def do_import_realm(import_dir: Path, subdomain: str, processes: int = 1) -> Rea # system if someone tries to signup just after doing import. RealmAuditLog.objects.create( realm=realm, - event_type=RealmAuditLog.REALM_IMPORTED, + event_type=AuditLogEventType.REALM_IMPORTED, event_time=timezone_now(), extra_data={ RealmAuditLog.ROLE_COUNT: realm_user_count_by_role(realm), diff --git a/zerver/lib/server_initialization.py b/zerver/lib/server_initialization.py index b35f9e5d00..fb0c8a0210 100644 --- a/zerver/lib/server_initialization.py +++ b/zerver/lib/server_initialization.py @@ -14,6 +14,7 @@ from zerver.models import ( ) from zerver.models.clients import get_client from zerver.models.presence import PresenceSequence +from zerver.models.realm_audit_logs import AuditLogEventType from zerver.models.users import get_system_bot from zproject.backends import all_default_backend_names @@ -37,7 +38,7 @@ def create_internal_realm() -> None: realm.save() RealmAuditLog.objects.create( - realm=realm, event_type=RealmAuditLog.REALM_CREATED, event_time=realm.date_created + realm=realm, event_type=AuditLogEventType.REALM_CREATED, event_time=realm.date_created ) RealmUserDefault.objects.create(realm=realm) create_system_user_groups_for_realm(realm) diff --git a/zerver/models/realm_audit_logs.py b/zerver/models/realm_audit_logs.py index a24ee5bea4..c8010770e0 100644 --- a/zerver/models/realm_audit_logs.py +++ b/zerver/models/realm_audit_logs.py @@ -50,6 +50,21 @@ class AuditLogEventType(IntEnum): REALM_REACTIVATION_EMAIL_SENT = 212 REALM_SPONSORSHIP_PENDING_STATUS_CHANGED = 213 REALM_SUBDOMAIN_CHANGED = 214 + REALM_CREATED = 215 + REALM_DEFAULT_USER_SETTINGS_CHANGED = 216 + REALM_ORG_TYPE_CHANGED = 217 + REALM_DOMAIN_ADDED = 218 + REALM_DOMAIN_CHANGED = 219 + REALM_DOMAIN_REMOVED = 220 + REALM_PLAYGROUND_ADDED = 221 + REALM_PLAYGROUND_REMOVED = 222 + REALM_LINKIFIER_ADDED = 223 + REALM_LINKIFIER_CHANGED = 224 + REALM_LINKIFIER_REMOVED = 225 + REALM_EMOJI_ADDED = 226 + REALM_EMOJI_REMOVED = 227 + REALM_LINKIFIERS_REORDERED = 228 + REALM_IMPORTED = 229 class AbstractRealmAuditLog(models.Model): @@ -71,22 +86,6 @@ class AbstractRealmAuditLog(models.Model): extra_data = models.JSONField(default=dict, encoder=DjangoJSONEncoder) # Event types - REALM_CREATED = 215 - REALM_DEFAULT_USER_SETTINGS_CHANGED = 216 - REALM_ORG_TYPE_CHANGED = 217 - REALM_DOMAIN_ADDED = 218 - REALM_DOMAIN_CHANGED = 219 - REALM_DOMAIN_REMOVED = 220 - REALM_PLAYGROUND_ADDED = 221 - REALM_PLAYGROUND_REMOVED = 222 - REALM_LINKIFIER_ADDED = 223 - REALM_LINKIFIER_CHANGED = 224 - REALM_LINKIFIER_REMOVED = 225 - REALM_EMOJI_ADDED = 226 - REALM_EMOJI_REMOVED = 227 - REALM_LINKIFIERS_REORDERED = 228 - REALM_IMPORTED = 229 - SUBSCRIPTION_CREATED = 301 SUBSCRIPTION_ACTIVATED = 302 SUBSCRIPTION_DEACTIVATED = 303 @@ -162,7 +161,7 @@ class AbstractRealmAuditLog(models.Model): AuditLogEventType.USER_ROLE_CHANGED, AuditLogEventType.REALM_DEACTIVATED, AuditLogEventType.REALM_REACTIVATED, - REALM_IMPORTED, + AuditLogEventType.REALM_IMPORTED, ] HOW_REALM_CREATOR_FOUND_ZULIP_OPTIONS = { diff --git a/zerver/tests/test_audit_log.py b/zerver/tests/test_audit_log.py index cd775396b8..10c4909f30 100644 --- a/zerver/tests/test_audit_log.py +++ b/zerver/tests/test_audit_log.py @@ -829,7 +829,7 @@ class TestRealmAuditLog(ZulipTestCase): self.assertEqual( RealmAuditLog.objects.filter( realm=user.realm, - event_type=RealmAuditLog.REALM_DOMAIN_ADDED, + event_type=AuditLogEventType.REALM_DOMAIN_ADDED, event_time__gte=now, acting_user=user, extra_data=expected_extra_data, @@ -850,7 +850,7 @@ class TestRealmAuditLog(ZulipTestCase): self.assertEqual( RealmAuditLog.objects.filter( realm=user.realm, - event_type=RealmAuditLog.REALM_DOMAIN_CHANGED, + event_type=AuditLogEventType.REALM_DOMAIN_CHANGED, event_time__gte=now, acting_user=user, extra_data=expected_extra_data, @@ -871,7 +871,7 @@ class TestRealmAuditLog(ZulipTestCase): self.assertEqual( RealmAuditLog.objects.filter( realm=user.realm, - event_type=RealmAuditLog.REALM_DOMAIN_REMOVED, + event_type=AuditLogEventType.REALM_DOMAIN_REMOVED, event_time__gte=now, acting_user=user, extra_data=expected_extra_data, @@ -903,7 +903,7 @@ class TestRealmAuditLog(ZulipTestCase): self.assertEqual( RealmAuditLog.objects.filter( realm=user.realm, - event_type=RealmAuditLog.REALM_PLAYGROUND_ADDED, + event_type=AuditLogEventType.REALM_PLAYGROUND_ADDED, event_time__gte=now, acting_user=user, extra_data=expected_extra_data, @@ -930,7 +930,7 @@ class TestRealmAuditLog(ZulipTestCase): self.assertEqual( RealmAuditLog.objects.filter( realm=user.realm, - event_type=RealmAuditLog.REALM_PLAYGROUND_REMOVED, + event_type=AuditLogEventType.REALM_PLAYGROUND_REMOVED, event_time__gte=now, acting_user=user, extra_data=expected_extra_data, @@ -961,7 +961,7 @@ class TestRealmAuditLog(ZulipTestCase): self.assertEqual( RealmAuditLog.objects.filter( realm=user.realm, - event_type=RealmAuditLog.REALM_LINKIFIER_ADDED, + event_type=AuditLogEventType.REALM_LINKIFIER_ADDED, event_time__gte=now, acting_user=user, extra_data=expected_extra_data, @@ -989,7 +989,7 @@ class TestRealmAuditLog(ZulipTestCase): self.assertEqual( RealmAuditLog.objects.filter( realm=user.realm, - event_type=RealmAuditLog.REALM_LINKIFIER_CHANGED, + event_type=AuditLogEventType.REALM_LINKIFIER_CHANGED, event_time__gte=now, acting_user=user, extra_data=expected_extra_data, @@ -1014,7 +1014,7 @@ class TestRealmAuditLog(ZulipTestCase): self.assertEqual( RealmAuditLog.objects.filter( realm=user.realm, - event_type=RealmAuditLog.REALM_LINKIFIER_REMOVED, + event_type=AuditLogEventType.REALM_LINKIFIER_REMOVED, event_time__gte=now, acting_user=user, extra_data=expected_extra_data, @@ -1058,7 +1058,7 @@ class TestRealmAuditLog(ZulipTestCase): self.assertEqual( RealmAuditLog.objects.filter( realm=user.realm, - event_type=RealmAuditLog.REALM_EMOJI_ADDED, + event_type=AuditLogEventType.REALM_EMOJI_ADDED, event_time__gte=now, acting_user=user, extra_data=expected_extra_data, @@ -1089,7 +1089,7 @@ class TestRealmAuditLog(ZulipTestCase): self.assertEqual( RealmAuditLog.objects.filter( realm=user.realm, - event_type=RealmAuditLog.REALM_EMOJI_REMOVED, + event_type=AuditLogEventType.REALM_EMOJI_REMOVED, event_time__gte=now, acting_user=user, extra_data=expected_extra_data, diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py index acd5b4d4a0..9e0480b47e 100644 --- a/zerver/tests/test_events.py +++ b/zerver/tests/test_events.py @@ -3853,7 +3853,7 @@ class RealmPropertyActionTest(BaseAction): self.assertEqual( RealmAuditLog.objects.filter( realm=self.user_profile.realm, - event_type=RealmAuditLog.REALM_DEFAULT_USER_SETTINGS_CHANGED, + event_type=AuditLogEventType.REALM_DEFAULT_USER_SETTINGS_CHANGED, event_time__gte=now, acting_user=self.user_profile, ).count(), @@ -3874,7 +3874,7 @@ class RealmPropertyActionTest(BaseAction): self.assertEqual( RealmAuditLog.objects.filter( realm=self.user_profile.realm, - event_type=RealmAuditLog.REALM_DEFAULT_USER_SETTINGS_CHANGED, + event_type=AuditLogEventType.REALM_DEFAULT_USER_SETTINGS_CHANGED, event_time__gte=now, acting_user=self.user_profile, extra_data={ diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.py index 82acf4d88a..3400a61d83 100644 --- a/zerver/tests/test_import_export.py +++ b/zerver/tests/test_import_export.py @@ -1325,7 +1325,7 @@ class RealmImportExportTest(ExportFile): event_type__in=[ AuditLogEventType.REALM_PLAN_TYPE_CHANGED, RealmAuditLog.STREAM_CREATED, - RealmAuditLog.REALM_IMPORTED, + AuditLogEventType.REALM_IMPORTED, ] ) realmauditlog_event_type = {log.event_type for log in realmauditlogs} diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.py index 11152e0a5a..d7c5b89068 100644 --- a/zerver/tests/test_realm.py +++ b/zerver/tests/test_realm.py @@ -1006,7 +1006,7 @@ class RealmTest(ZulipTestCase): do_change_realm_org_type(realm, Realm.ORG_TYPES["government"]["id"], acting_user=iago) realm = get_realm("zulip") realm_audit_log = RealmAuditLog.objects.filter( - event_type=RealmAuditLog.REALM_ORG_TYPE_CHANGED + event_type=AuditLogEventType.REALM_ORG_TYPE_CHANGED ).last() assert realm_audit_log is not None expected_extra_data = { @@ -1375,7 +1375,9 @@ class RealmTest(ZulipTestCase): self.assertTrue( RealmAuditLog.objects.filter( - realm=realm, event_type=RealmAuditLog.REALM_CREATED, event_time=realm.date_created + realm=realm, + event_type=AuditLogEventType.REALM_CREATED, + event_time=realm.date_created, ).exists() ) @@ -1421,7 +1423,9 @@ class RealmTest(ZulipTestCase): self.assertTrue( RealmAuditLog.objects.filter( - realm=realm, event_type=RealmAuditLog.REALM_CREATED, event_time=realm.date_created + realm=realm, + event_type=AuditLogEventType.REALM_CREATED, + event_time=realm.date_created, ).exists() ) diff --git a/zerver/tests/test_realm_linkifiers.py b/zerver/tests/test_realm_linkifiers.py index 59115ec601..1ec6686e0d 100644 --- a/zerver/tests/test_realm_linkifiers.py +++ b/zerver/tests/test_realm_linkifiers.py @@ -7,6 +7,7 @@ from typing_extensions import override from zerver.lib.test_classes import ZulipTestCase from zerver.models import RealmAuditLog, RealmFilter from zerver.models.linkifiers import url_template_validator +from zerver.models.realm_audit_logs import AuditLogEventType class RealmFilterTest(ZulipTestCase): @@ -278,7 +279,7 @@ class RealmFilterTest(ZulipTestCase): """Check if the audit log created orders the linkifiers correctly""" extra_data = ( RealmAuditLog.objects.filter( - acting_user=iago, event_type=RealmAuditLog.REALM_LINKIFIERS_REORDERED + acting_user=iago, event_type=AuditLogEventType.REALM_LINKIFIERS_REORDERED ) .latest("event_time") .extra_data @@ -307,7 +308,7 @@ class RealmFilterTest(ZulipTestCase): reorder_verify_succeed([]) self.assertEqual( RealmAuditLog.objects.filter( - realm=iago.realm, event_type=RealmAuditLog.REALM_LINKIFIERS_REORDERED + realm=iago.realm, event_type=AuditLogEventType.REALM_LINKIFIERS_REORDERED ).count(), 0, ) diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py index 6e10c3c85e..cbe4051dc9 100644 --- a/zerver/tests/test_signup.py +++ b/zerver/tests/test_signup.py @@ -79,6 +79,7 @@ from zerver.models import ( UserMessage, UserProfile, ) +from zerver.models.realm_audit_logs import AuditLogEventType from zerver.models.realms import get_realm from zerver.models.recipients import get_direct_message_group_user_ids from zerver.models.streams import get_stream @@ -1448,7 +1449,7 @@ class RealmCreationTest(ZulipTestCase): self.assertEqual("new organizations", messages[0].topic_name()) realm_creation_audit_log = RealmAuditLog.objects.get( - realm=realm, event_type=RealmAuditLog.REALM_CREATED + realm=realm, event_type=AuditLogEventType.REALM_CREATED ) self.assertEqual(realm_creation_audit_log.acting_user, user) self.assertEqual(realm_creation_audit_log.event_time, realm.date_created) diff --git a/zerver/tests/test_slack_importer.py b/zerver/tests/test_slack_importer.py index 798aea05eb..991f95d9f3 100644 --- a/zerver/tests/test_slack_importer.py +++ b/zerver/tests/test_slack_importer.py @@ -1358,8 +1358,8 @@ class SlackImporter(ZulipTestCase): RealmAuditLog.SUBSCRIPTION_CREATED, AuditLogEventType.REALM_PLAN_TYPE_CHANGED, AuditLogEventType.REALM_PROPERTY_CHANGED, - RealmAuditLog.REALM_CREATED, - RealmAuditLog.REALM_IMPORTED, + AuditLogEventType.REALM_CREATED, + AuditLogEventType.REALM_IMPORTED, RealmAuditLog.USER_GROUP_CREATED, RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED, RealmAuditLog.USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_ADDED,