mirror of https://github.com/zulip/zulip.git
audit-log: Move stream/channel event types to AuditLogEventType enum.
Renamed event types below in the enum class to use channel instead of stream. Event types moved: STREAM_CREATED, STREAM_DEACTIVATED, STREAM_NAME_CHANGED STREAM_REACTIVATED, STREAM_MESSAGE_RETENTION_DAYS_CHANGED STREAM_PROPERTY_CHANGED, STREAM_GROUP_BASED_SETTING_CHANGED
This commit is contained in:
parent
f7e07e91a2
commit
df1e9093a9
|
@ -203,7 +203,7 @@ def do_deactivate_stream(stream: Stream, *, acting_user: UserProfile | None) ->
|
|||
realm=stream.realm,
|
||||
acting_user=acting_user,
|
||||
modified_stream=stream,
|
||||
event_type=RealmAuditLog.STREAM_DEACTIVATED,
|
||||
event_type=AuditLogEventType.CHANNEL_DEACTIVATED,
|
||||
event_time=event_time,
|
||||
)
|
||||
|
||||
|
@ -286,7 +286,7 @@ def do_unarchive_stream(stream: Stream, new_name: str, *, acting_user: UserProfi
|
|||
realm=realm,
|
||||
acting_user=acting_user,
|
||||
modified_stream=stream,
|
||||
event_type=RealmAuditLog.STREAM_REACTIVATED,
|
||||
event_type=AuditLogEventType.CHANNEL_REACTIVATED,
|
||||
event_time=timezone_now(),
|
||||
)
|
||||
|
||||
|
@ -1226,7 +1226,7 @@ def do_change_stream_permission(
|
|||
realm=realm,
|
||||
acting_user=acting_user,
|
||||
modified_stream=stream,
|
||||
event_type=RealmAuditLog.STREAM_PROPERTY_CHANGED,
|
||||
event_type=AuditLogEventType.CHANNEL_PROPERTY_CHANGED,
|
||||
event_time=event_time,
|
||||
extra_data={
|
||||
RealmAuditLog.OLD_VALUE: old_invite_only_value,
|
||||
|
@ -1240,7 +1240,7 @@ def do_change_stream_permission(
|
|||
realm=realm,
|
||||
acting_user=acting_user,
|
||||
modified_stream=stream,
|
||||
event_type=RealmAuditLog.STREAM_PROPERTY_CHANGED,
|
||||
event_type=AuditLogEventType.CHANNEL_PROPERTY_CHANGED,
|
||||
event_time=event_time,
|
||||
extra_data={
|
||||
RealmAuditLog.OLD_VALUE: old_history_public_to_subscribers_value,
|
||||
|
@ -1266,7 +1266,7 @@ def do_change_stream_permission(
|
|||
realm=realm,
|
||||
acting_user=acting_user,
|
||||
modified_stream=stream,
|
||||
event_type=RealmAuditLog.STREAM_PROPERTY_CHANGED,
|
||||
event_type=AuditLogEventType.CHANNEL_PROPERTY_CHANGED,
|
||||
event_time=event_time,
|
||||
extra_data={
|
||||
RealmAuditLog.OLD_VALUE: old_is_web_public_value,
|
||||
|
@ -1376,7 +1376,7 @@ def do_change_stream_post_policy(
|
|||
realm=stream.realm,
|
||||
acting_user=acting_user,
|
||||
modified_stream=stream,
|
||||
event_type=RealmAuditLog.STREAM_PROPERTY_CHANGED,
|
||||
event_type=AuditLogEventType.CHANNEL_PROPERTY_CHANGED,
|
||||
event_time=timezone_now(),
|
||||
extra_data={
|
||||
RealmAuditLog.OLD_VALUE: old_post_policy,
|
||||
|
@ -1427,7 +1427,7 @@ def do_rename_stream(stream: Stream, new_name: str, user_profile: UserProfile) -
|
|||
realm=stream.realm,
|
||||
acting_user=user_profile,
|
||||
modified_stream=stream,
|
||||
event_type=RealmAuditLog.STREAM_NAME_CHANGED,
|
||||
event_type=AuditLogEventType.CHANNEL_NAME_CHANGED,
|
||||
event_time=timezone_now(),
|
||||
extra_data={
|
||||
RealmAuditLog.OLD_VALUE: old_name,
|
||||
|
@ -1516,7 +1516,7 @@ def do_change_stream_description(
|
|||
realm=stream.realm,
|
||||
acting_user=acting_user,
|
||||
modified_stream=stream,
|
||||
event_type=RealmAuditLog.STREAM_PROPERTY_CHANGED,
|
||||
event_type=AuditLogEventType.CHANNEL_PROPERTY_CHANGED,
|
||||
event_time=timezone_now(),
|
||||
extra_data={
|
||||
RealmAuditLog.OLD_VALUE: old_description,
|
||||
|
@ -1603,7 +1603,7 @@ def do_change_stream_message_retention_days(
|
|||
realm=stream.realm,
|
||||
acting_user=acting_user,
|
||||
modified_stream=stream,
|
||||
event_type=RealmAuditLog.STREAM_MESSAGE_RETENTION_DAYS_CHANGED,
|
||||
event_type=AuditLogEventType.CHANNEL_MESSAGE_RETENTION_DAYS_CHANGED,
|
||||
event_time=timezone_now(),
|
||||
extra_data={
|
||||
RealmAuditLog.OLD_VALUE: old_message_retention_days_value,
|
||||
|
@ -1647,7 +1647,7 @@ def do_change_stream_group_based_setting(
|
|||
realm=stream.realm,
|
||||
acting_user=acting_user,
|
||||
modified_stream=stream,
|
||||
event_type=RealmAuditLog.STREAM_GROUP_BASED_SETTING_CHANGED,
|
||||
event_type=AuditLogEventType.CHANNEL_GROUP_BASED_SETTING_CHANGED,
|
||||
event_time=timezone_now(),
|
||||
extra_data={
|
||||
RealmAuditLog.OLD_VALUE: old_user_group_id,
|
||||
|
|
|
@ -35,6 +35,7 @@ from zerver.models import (
|
|||
UserProfile,
|
||||
)
|
||||
from zerver.models.groups import SystemGroups
|
||||
from zerver.models.realm_audit_logs import AuditLogEventType
|
||||
from zerver.models.streams import (
|
||||
bulk_get_streams,
|
||||
get_realm_stream,
|
||||
|
@ -182,7 +183,7 @@ def create_stream_if_needed(
|
|||
realm=realm,
|
||||
acting_user=acting_user,
|
||||
modified_stream=stream,
|
||||
event_type=RealmAuditLog.STREAM_CREATED,
|
||||
event_type=AuditLogEventType.CHANNEL_CREATED,
|
||||
event_time=event_time,
|
||||
)
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ from typing_extensions import override
|
|||
from zerver.actions.streams import deactivated_streams_by_old_name, do_unarchive_stream
|
||||
from zerver.lib.management import ZulipBaseCommand
|
||||
from zerver.models import RealmAuditLog, Stream
|
||||
from zerver.models.realm_audit_logs import AuditLogEventType
|
||||
|
||||
|
||||
class Command(ZulipBaseCommand):
|
||||
|
@ -70,7 +71,7 @@ class Command(ZulipBaseCommand):
|
|||
RealmAuditLog.objects.filter(
|
||||
realm=realm,
|
||||
modified_stream=channel,
|
||||
event_type=RealmAuditLog.STREAM_DEACTIVATED,
|
||||
event_type=AuditLogEventType.CHANNEL_DEACTIVATED,
|
||||
)
|
||||
.order_by("-id")
|
||||
.first()
|
||||
|
|
|
@ -86,6 +86,14 @@ class AuditLogEventType(IntEnum):
|
|||
CUSTOMER_PROPERTY_CHANGED = 505
|
||||
CUSTOMER_PLAN_PROPERTY_CHANGED = 506
|
||||
|
||||
CHANNEL_CREATED = 601
|
||||
CHANNEL_DEACTIVATED = 602
|
||||
CHANNEL_NAME_CHANGED = 603
|
||||
CHANNEL_REACTIVATED = 604
|
||||
CHANNEL_MESSAGE_RETENTION_DAYS_CHANGED = 605
|
||||
CHANNEL_PROPERTY_CHANGED = 607
|
||||
CHANNEL_GROUP_BASED_SETTING_CHANGED = 608
|
||||
|
||||
|
||||
class AbstractRealmAuditLog(models.Model):
|
||||
"""Defines fields common to RealmAuditLog and RemoteRealmAuditLog."""
|
||||
|
@ -106,14 +114,6 @@ class AbstractRealmAuditLog(models.Model):
|
|||
extra_data = models.JSONField(default=dict, encoder=DjangoJSONEncoder)
|
||||
|
||||
# Event types
|
||||
STREAM_CREATED = 601
|
||||
STREAM_DEACTIVATED = 602
|
||||
STREAM_NAME_CHANGED = 603
|
||||
STREAM_REACTIVATED = 604
|
||||
STREAM_MESSAGE_RETENTION_DAYS_CHANGED = 605
|
||||
STREAM_PROPERTY_CHANGED = 607
|
||||
STREAM_GROUP_BASED_SETTING_CHANGED = 608
|
||||
|
||||
USER_GROUP_CREATED = 701
|
||||
USER_GROUP_DELETED = 702
|
||||
USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED = 703
|
||||
|
|
|
@ -456,7 +456,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
|||
self.assertEqual(
|
||||
RealmAuditLog.objects.filter(
|
||||
realm=realm,
|
||||
event_type=RealmAuditLog.STREAM_CREATED,
|
||||
event_type=AuditLogEventType.CHANNEL_CREATED,
|
||||
event_time__gte=now,
|
||||
acting_user=user,
|
||||
modified_stream=stream,
|
||||
|
@ -474,7 +474,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
|||
self.assertEqual(
|
||||
RealmAuditLog.objects.filter(
|
||||
realm=realm,
|
||||
event_type=RealmAuditLog.STREAM_DEACTIVATED,
|
||||
event_type=AuditLogEventType.CHANNEL_DEACTIVATED,
|
||||
event_time__gte=now,
|
||||
acting_user=user,
|
||||
modified_stream=stream,
|
||||
|
@ -759,7 +759,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
|||
self.assertEqual(
|
||||
RealmAuditLog.objects.filter(
|
||||
realm=user.realm,
|
||||
event_type=RealmAuditLog.STREAM_NAME_CHANGED,
|
||||
event_type=AuditLogEventType.CHANNEL_NAME_CHANGED,
|
||||
event_time__gte=now,
|
||||
acting_user=user,
|
||||
modified_stream=stream,
|
||||
|
|
|
@ -1324,7 +1324,7 @@ class RealmImportExportTest(ExportFile):
|
|||
realmauditlogs = RealmAuditLog.objects.filter(realm=r).exclude(
|
||||
event_type__in=[
|
||||
AuditLogEventType.REALM_PLAN_TYPE_CHANGED,
|
||||
RealmAuditLog.STREAM_CREATED,
|
||||
AuditLogEventType.CHANNEL_CREATED,
|
||||
AuditLogEventType.REALM_IMPORTED,
|
||||
]
|
||||
)
|
||||
|
|
|
@ -120,6 +120,7 @@ from zerver.models import (
|
|||
UserProfile,
|
||||
)
|
||||
from zerver.models.groups import SystemGroups
|
||||
from zerver.models.realm_audit_logs import AuditLogEventType
|
||||
from zerver.models.realms import CommonPolicyEnum, get_realm
|
||||
from zerver.models.streams import get_default_stream_groups, get_stream
|
||||
from zerver.models.users import active_non_guest_user_ids, get_user, get_user_profile_by_id_in_realm
|
||||
|
@ -691,7 +692,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
self.assertEqual(messages[0].content, expected_notification)
|
||||
|
||||
history_public_to_subscribers_log = RealmAuditLog.objects.filter(
|
||||
event_type=RealmAuditLog.STREAM_PROPERTY_CHANGED,
|
||||
event_type=AuditLogEventType.CHANNEL_PROPERTY_CHANGED,
|
||||
modified_stream=stream,
|
||||
).last()
|
||||
assert history_public_to_subscribers_log is not None
|
||||
|
@ -704,7 +705,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
self.assertEqual(history_public_to_subscribers_log.extra_data, expected_extra_data)
|
||||
|
||||
invite_only_log = RealmAuditLog.objects.filter(
|
||||
event_type=RealmAuditLog.STREAM_PROPERTY_CHANGED,
|
||||
event_type=AuditLogEventType.CHANNEL_PROPERTY_CHANGED,
|
||||
modified_stream=stream,
|
||||
).order_by("-id")[1]
|
||||
assert invite_only_log is not None
|
||||
|
@ -752,7 +753,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
self.assertEqual(messages[0].content, expected_notification)
|
||||
|
||||
history_public_to_subscribers_log = RealmAuditLog.objects.filter(
|
||||
event_type=RealmAuditLog.STREAM_PROPERTY_CHANGED,
|
||||
event_type=AuditLogEventType.CHANNEL_PROPERTY_CHANGED,
|
||||
modified_stream=stream,
|
||||
).last()
|
||||
assert history_public_to_subscribers_log is not None
|
||||
|
@ -765,7 +766,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
self.assertEqual(history_public_to_subscribers_log.extra_data, expected_extra_data)
|
||||
|
||||
invite_only_log = RealmAuditLog.objects.filter(
|
||||
event_type=RealmAuditLog.STREAM_PROPERTY_CHANGED,
|
||||
event_type=AuditLogEventType.CHANNEL_PROPERTY_CHANGED,
|
||||
modified_stream=stream,
|
||||
).order_by("-id")[1]
|
||||
assert invite_only_log is not None
|
||||
|
@ -872,7 +873,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
self.assertEqual(messages[0].content, expected_notification)
|
||||
|
||||
realm_audit_log = RealmAuditLog.objects.filter(
|
||||
event_type=RealmAuditLog.STREAM_PROPERTY_CHANGED,
|
||||
event_type=AuditLogEventType.CHANNEL_PROPERTY_CHANGED,
|
||||
modified_stream=stream,
|
||||
).last()
|
||||
assert realm_audit_log is not None
|
||||
|
@ -911,7 +912,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
self.assertEqual(messages[0].content, expected_notification)
|
||||
|
||||
realm_audit_log = RealmAuditLog.objects.filter(
|
||||
event_type=RealmAuditLog.STREAM_PROPERTY_CHANGED,
|
||||
event_type=AuditLogEventType.CHANNEL_PROPERTY_CHANGED,
|
||||
modified_stream=stream,
|
||||
).last()
|
||||
assert realm_audit_log is not None
|
||||
|
@ -950,7 +951,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
self.assertEqual(messages[0].content, expected_notification)
|
||||
|
||||
realm_audit_log = RealmAuditLog.objects.filter(
|
||||
event_type=RealmAuditLog.STREAM_PROPERTY_CHANGED,
|
||||
event_type=AuditLogEventType.CHANNEL_PROPERTY_CHANGED,
|
||||
modified_stream=stream,
|
||||
).last()
|
||||
assert realm_audit_log is not None
|
||||
|
@ -1048,7 +1049,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
self.assertEqual(messages[0].content, expected_notification)
|
||||
|
||||
realm_audit_log = RealmAuditLog.objects.filter(
|
||||
event_type=RealmAuditLog.STREAM_PROPERTY_CHANGED,
|
||||
event_type=AuditLogEventType.CHANNEL_PROPERTY_CHANGED,
|
||||
modified_stream=stream,
|
||||
).last()
|
||||
assert realm_audit_log is not None
|
||||
|
@ -1085,7 +1086,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
self.assertEqual(messages[0].content, expected_notification)
|
||||
|
||||
realm_audit_log = RealmAuditLog.objects.filter(
|
||||
event_type=RealmAuditLog.STREAM_PROPERTY_CHANGED,
|
||||
event_type=AuditLogEventType.CHANNEL_PROPERTY_CHANGED,
|
||||
modified_stream=stream,
|
||||
).last()
|
||||
assert realm_audit_log is not None
|
||||
|
@ -1115,7 +1116,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
self.assertEqual(messages[1].content, expected_notification)
|
||||
|
||||
realm_audit_log = RealmAuditLog.objects.filter(
|
||||
event_type=RealmAuditLog.STREAM_PROPERTY_CHANGED,
|
||||
event_type=AuditLogEventType.CHANNEL_PROPERTY_CHANGED,
|
||||
modified_stream=stream,
|
||||
).last()
|
||||
assert realm_audit_log is not None
|
||||
|
@ -1959,7 +1960,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
self.assertEqual(messages[-1].content, expected_notification)
|
||||
|
||||
realm_audit_log = RealmAuditLog.objects.filter(
|
||||
event_type=RealmAuditLog.STREAM_PROPERTY_CHANGED,
|
||||
event_type=AuditLogEventType.CHANNEL_PROPERTY_CHANGED,
|
||||
modified_stream=stream,
|
||||
).last()
|
||||
assert realm_audit_log is not None
|
||||
|
@ -2021,7 +2022,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
self.assertEqual(messages[-1].content, expected_notification)
|
||||
|
||||
realm_audit_log = RealmAuditLog.objects.filter(
|
||||
event_type=RealmAuditLog.STREAM_PROPERTY_CHANGED,
|
||||
event_type=AuditLogEventType.CHANNEL_PROPERTY_CHANGED,
|
||||
modified_stream=stream,
|
||||
).last()
|
||||
assert realm_audit_log is not None
|
||||
|
@ -2085,7 +2086,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
self.assertEqual(messages[-1].content, expected_notification)
|
||||
|
||||
realm_audit_log = RealmAuditLog.objects.filter(
|
||||
event_type=RealmAuditLog.STREAM_PROPERTY_CHANGED,
|
||||
event_type=AuditLogEventType.CHANNEL_PROPERTY_CHANGED,
|
||||
modified_stream=stream,
|
||||
).last()
|
||||
assert realm_audit_log is not None
|
||||
|
@ -2118,7 +2119,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
)
|
||||
self.assertEqual(messages[0].content, expected_notification)
|
||||
realm_audit_log = RealmAuditLog.objects.filter(
|
||||
event_type=RealmAuditLog.STREAM_MESSAGE_RETENTION_DAYS_CHANGED
|
||||
event_type=AuditLogEventType.CHANNEL_MESSAGE_RETENTION_DAYS_CHANGED
|
||||
).last()
|
||||
assert realm_audit_log is not None
|
||||
expected_extra_data = {RealmAuditLog.OLD_VALUE: None, RealmAuditLog.NEW_VALUE: 2}
|
||||
|
@ -2139,7 +2140,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
)
|
||||
self.assertEqual(messages[1].content, expected_notification)
|
||||
realm_audit_log = RealmAuditLog.objects.filter(
|
||||
event_type=RealmAuditLog.STREAM_MESSAGE_RETENTION_DAYS_CHANGED
|
||||
event_type=AuditLogEventType.CHANNEL_MESSAGE_RETENTION_DAYS_CHANGED
|
||||
).last()
|
||||
assert realm_audit_log is not None
|
||||
expected_extra_data = {RealmAuditLog.OLD_VALUE: 2, RealmAuditLog.NEW_VALUE: 8}
|
||||
|
@ -2161,7 +2162,7 @@ class StreamAdminTest(ZulipTestCase):
|
|||
)
|
||||
self.assertEqual(messages[2].content, expected_notification)
|
||||
realm_audit_log = RealmAuditLog.objects.filter(
|
||||
event_type=RealmAuditLog.STREAM_MESSAGE_RETENTION_DAYS_CHANGED
|
||||
event_type=AuditLogEventType.CHANNEL_MESSAGE_RETENTION_DAYS_CHANGED
|
||||
).last()
|
||||
assert realm_audit_log is not None
|
||||
expected_extra_data = {
|
||||
|
|
Loading…
Reference in New Issue