mirror of https://github.com/zulip/zulip.git
audit-log: Move user group event types to AuditLogEventType enum.
Event types moved: USER_GROUP_CREATED, USER_GROUP_DELETED USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED, USER_GROUP_DIRECT_USER_MEMBERSHIP_REMOVED, USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_ADDED, USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_REMOVED, USER_GROUP_DIRECT_SUPERGROUP_MEMBERSHIP_ADDED, USER_GROUP_DIRECT_SUPERGROUP_MEMBERSHIP_REMOVED, USER_GROUP_NAME_CHANGED, USER_GROUP_DESCRIPTION_CHANGED, USER_GROUP_GROUP_BASED_SETTING_CHANGED
This commit is contained in:
parent
df1e9093a9
commit
d431a5aad6
|
@ -572,7 +572,7 @@ def do_create_user(
|
||||||
realm=user_profile.realm,
|
realm=user_profile.realm,
|
||||||
modified_user=user_profile,
|
modified_user=user_profile,
|
||||||
modified_user_group=system_user_group,
|
modified_user_group=system_user_group,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
||||||
event_time=event_time,
|
event_time=event_time,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
)
|
)
|
||||||
|
@ -590,7 +590,7 @@ def do_create_user(
|
||||||
realm=user_profile.realm,
|
realm=user_profile.realm,
|
||||||
modified_user=user_profile,
|
modified_user=user_profile,
|
||||||
modified_user_group=full_members_system_group,
|
modified_user_group=full_members_system_group,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
||||||
event_time=event_time,
|
event_time=event_time,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
)
|
)
|
||||||
|
|
|
@ -25,6 +25,7 @@ from zerver.models import (
|
||||||
UserProfile,
|
UserProfile,
|
||||||
)
|
)
|
||||||
from zerver.models.groups import SystemGroups
|
from zerver.models.groups import SystemGroups
|
||||||
|
from zerver.models.realm_audit_logs import AuditLogEventType
|
||||||
from zerver.models.users import active_user_ids
|
from zerver.models.users import active_user_ids
|
||||||
from zerver.tornado.django_api import send_event_on_commit
|
from zerver.tornado.django_api import send_event_on_commit
|
||||||
|
|
||||||
|
@ -72,7 +73,7 @@ def create_user_group_in_database(
|
||||||
RealmAuditLog(
|
RealmAuditLog(
|
||||||
realm=realm,
|
realm=realm,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
event_type=RealmAuditLog.USER_GROUP_CREATED,
|
event_type=AuditLogEventType.USER_GROUP_CREATED,
|
||||||
event_time=creation_time,
|
event_time=creation_time,
|
||||||
modified_user_group=user_group,
|
modified_user_group=user_group,
|
||||||
),
|
),
|
||||||
|
@ -80,7 +81,7 @@ def create_user_group_in_database(
|
||||||
RealmAuditLog(
|
RealmAuditLog(
|
||||||
realm=realm,
|
realm=realm,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
||||||
event_time=creation_time,
|
event_time=creation_time,
|
||||||
modified_user=member,
|
modified_user=member,
|
||||||
modified_user_group=user_group,
|
modified_user_group=user_group,
|
||||||
|
@ -228,7 +229,7 @@ def do_update_user_group_name(
|
||||||
RealmAuditLog.objects.create(
|
RealmAuditLog.objects.create(
|
||||||
realm=user_group.realm,
|
realm=user_group.realm,
|
||||||
modified_user_group=user_group,
|
modified_user_group=user_group,
|
||||||
event_type=RealmAuditLog.USER_GROUP_NAME_CHANGED,
|
event_type=AuditLogEventType.USER_GROUP_NAME_CHANGED,
|
||||||
event_time=timezone_now(),
|
event_time=timezone_now(),
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
extra_data={
|
extra_data={
|
||||||
|
@ -251,7 +252,7 @@ def do_update_user_group_description(
|
||||||
RealmAuditLog.objects.create(
|
RealmAuditLog.objects.create(
|
||||||
realm=user_group.realm,
|
realm=user_group.realm,
|
||||||
modified_user_group=user_group,
|
modified_user_group=user_group,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DESCRIPTION_CHANGED,
|
event_type=AuditLogEventType.USER_GROUP_DESCRIPTION_CHANGED,
|
||||||
event_time=timezone_now(),
|
event_time=timezone_now(),
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
extra_data={
|
extra_data={
|
||||||
|
@ -293,7 +294,7 @@ def bulk_add_members_to_user_groups(
|
||||||
realm=user_group.realm,
|
realm=user_group.realm,
|
||||||
modified_user_id=user_id,
|
modified_user_id=user_id,
|
||||||
modified_user_group=user_group,
|
modified_user_group=user_group,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
||||||
event_time=now,
|
event_time=now,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
)
|
)
|
||||||
|
@ -326,7 +327,7 @@ def bulk_remove_members_from_user_groups(
|
||||||
realm=user_group.realm,
|
realm=user_group.realm,
|
||||||
modified_user_id=user_id,
|
modified_user_id=user_id,
|
||||||
modified_user_group=user_group,
|
modified_user_group=user_group,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_REMOVED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_USER_MEMBERSHIP_REMOVED,
|
||||||
event_time=now,
|
event_time=now,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
)
|
)
|
||||||
|
@ -365,7 +366,7 @@ def add_subgroups_to_user_group(
|
||||||
RealmAuditLog(
|
RealmAuditLog(
|
||||||
realm=user_group.realm,
|
realm=user_group.realm,
|
||||||
modified_user_group=user_group,
|
modified_user_group=user_group,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_ADDED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_ADDED,
|
||||||
event_time=now,
|
event_time=now,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
extra_data={"subgroup_ids": subgroup_ids},
|
extra_data={"subgroup_ids": subgroup_ids},
|
||||||
|
@ -374,7 +375,7 @@ def add_subgroups_to_user_group(
|
||||||
RealmAuditLog(
|
RealmAuditLog(
|
||||||
realm=user_group.realm,
|
realm=user_group.realm,
|
||||||
modified_user_group_id=subgroup_id,
|
modified_user_group_id=subgroup_id,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_SUPERGROUP_MEMBERSHIP_ADDED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_SUPERGROUP_MEMBERSHIP_ADDED,
|
||||||
event_time=now,
|
event_time=now,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
extra_data={"supergroup_ids": [user_group.id]},
|
extra_data={"supergroup_ids": [user_group.id]},
|
||||||
|
@ -402,7 +403,7 @@ def remove_subgroups_from_user_group(
|
||||||
RealmAuditLog(
|
RealmAuditLog(
|
||||||
realm=user_group.realm,
|
realm=user_group.realm,
|
||||||
modified_user_group=user_group,
|
modified_user_group=user_group,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_REMOVED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_REMOVED,
|
||||||
event_time=now,
|
event_time=now,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
extra_data={"subgroup_ids": subgroup_ids},
|
extra_data={"subgroup_ids": subgroup_ids},
|
||||||
|
@ -411,7 +412,7 @@ def remove_subgroups_from_user_group(
|
||||||
RealmAuditLog(
|
RealmAuditLog(
|
||||||
realm=user_group.realm,
|
realm=user_group.realm,
|
||||||
modified_user_group_id=subgroup_id,
|
modified_user_group_id=subgroup_id,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_SUPERGROUP_MEMBERSHIP_REMOVED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_SUPERGROUP_MEMBERSHIP_REMOVED,
|
||||||
event_time=now,
|
event_time=now,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
extra_data={"supergroup_ids": [user_group.id]},
|
extra_data={"supergroup_ids": [user_group.id]},
|
||||||
|
@ -469,7 +470,7 @@ def do_change_user_group_permission_setting(
|
||||||
RealmAuditLog.objects.create(
|
RealmAuditLog.objects.create(
|
||||||
realm=user_group.realm,
|
realm=user_group.realm,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
event_type=RealmAuditLog.USER_GROUP_GROUP_BASED_SETTING_CHANGED,
|
event_type=AuditLogEventType.USER_GROUP_GROUP_BASED_SETTING_CHANGED,
|
||||||
event_time=timezone_now(),
|
event_time=timezone_now(),
|
||||||
modified_user_group=user_group,
|
modified_user_group=user_group,
|
||||||
extra_data={
|
extra_data={
|
||||||
|
|
|
@ -495,7 +495,7 @@ def do_change_user_role(
|
||||||
realm=user_profile.realm,
|
realm=user_profile.realm,
|
||||||
modified_user=user_profile,
|
modified_user=user_profile,
|
||||||
modified_user_group=old_system_group,
|
modified_user_group=old_system_group,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_REMOVED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_USER_MEMBERSHIP_REMOVED,
|
||||||
event_time=now,
|
event_time=now,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
),
|
),
|
||||||
|
@ -503,7 +503,7 @@ def do_change_user_role(
|
||||||
realm=user_profile.realm,
|
realm=user_profile.realm,
|
||||||
modified_user=user_profile,
|
modified_user=user_profile,
|
||||||
modified_user_group=system_group,
|
modified_user_group=system_group,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
||||||
event_time=now,
|
event_time=now,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
),
|
),
|
||||||
|
|
|
@ -154,7 +154,7 @@ def bulk_create_users(
|
||||||
realm=realm,
|
realm=realm,
|
||||||
modified_user=membership.user_profile,
|
modified_user=membership.user_profile,
|
||||||
modified_user_group=membership.user_group.named_user_group,
|
modified_user_group=membership.user_group.named_user_group,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
||||||
event_time=now,
|
event_time=now,
|
||||||
acting_user=None,
|
acting_user=None,
|
||||||
)
|
)
|
||||||
|
|
|
@ -1982,7 +1982,7 @@ def add_users_to_system_user_groups(
|
||||||
realm=realm,
|
realm=realm,
|
||||||
modified_user=membership.user_profile,
|
modified_user=membership.user_profile,
|
||||||
modified_user_group=membership.user_group.named_user_group,
|
modified_user_group=membership.user_group.named_user_group,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
||||||
event_time=now,
|
event_time=now,
|
||||||
acting_user=None,
|
acting_user=None,
|
||||||
)
|
)
|
||||||
|
|
|
@ -29,6 +29,7 @@ from zerver.models import (
|
||||||
UserProfile,
|
UserProfile,
|
||||||
)
|
)
|
||||||
from zerver.models.groups import SystemGroups
|
from zerver.models.groups import SystemGroups
|
||||||
|
from zerver.models.realm_audit_logs import AuditLogEventType
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -692,7 +693,7 @@ def create_system_user_groups_for_realm(realm: Realm) -> dict[int, NamedUserGrou
|
||||||
RealmAuditLog(
|
RealmAuditLog(
|
||||||
realm=realm,
|
realm=realm,
|
||||||
acting_user=None,
|
acting_user=None,
|
||||||
event_type=RealmAuditLog.USER_GROUP_CREATED,
|
event_type=AuditLogEventType.USER_GROUP_CREATED,
|
||||||
event_time=creation_time,
|
event_time=creation_time,
|
||||||
modified_user_group=user_group,
|
modified_user_group=user_group,
|
||||||
)
|
)
|
||||||
|
@ -718,7 +719,7 @@ def create_system_user_groups_for_realm(realm: Realm) -> dict[int, NamedUserGrou
|
||||||
RealmAuditLog(
|
RealmAuditLog(
|
||||||
realm=realm,
|
realm=realm,
|
||||||
modified_user_group=supergroup,
|
modified_user_group=supergroup,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_ADDED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_ADDED,
|
||||||
event_time=now,
|
event_time=now,
|
||||||
acting_user=None,
|
acting_user=None,
|
||||||
extra_data={"subgroup_ids": [subgroup.id]},
|
extra_data={"subgroup_ids": [subgroup.id]},
|
||||||
|
@ -726,7 +727,7 @@ def create_system_user_groups_for_realm(realm: Realm) -> dict[int, NamedUserGrou
|
||||||
RealmAuditLog(
|
RealmAuditLog(
|
||||||
realm=realm,
|
realm=realm,
|
||||||
modified_user_group=subgroup,
|
modified_user_group=subgroup,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_SUPERGROUP_MEMBERSHIP_ADDED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_SUPERGROUP_MEMBERSHIP_ADDED,
|
||||||
event_time=now,
|
event_time=now,
|
||||||
acting_user=None,
|
acting_user=None,
|
||||||
extra_data={"supergroup_ids": [supergroup.id]},
|
extra_data={"supergroup_ids": [supergroup.id]},
|
||||||
|
|
|
@ -94,6 +94,19 @@ class AuditLogEventType(IntEnum):
|
||||||
CHANNEL_PROPERTY_CHANGED = 607
|
CHANNEL_PROPERTY_CHANGED = 607
|
||||||
CHANNEL_GROUP_BASED_SETTING_CHANGED = 608
|
CHANNEL_GROUP_BASED_SETTING_CHANGED = 608
|
||||||
|
|
||||||
|
USER_GROUP_CREATED = 701
|
||||||
|
USER_GROUP_DELETED = 702
|
||||||
|
USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED = 703
|
||||||
|
USER_GROUP_DIRECT_USER_MEMBERSHIP_REMOVED = 704
|
||||||
|
USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_ADDED = 705
|
||||||
|
USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_REMOVED = 706
|
||||||
|
USER_GROUP_DIRECT_SUPERGROUP_MEMBERSHIP_ADDED = 707
|
||||||
|
USER_GROUP_DIRECT_SUPERGROUP_MEMBERSHIP_REMOVED = 708
|
||||||
|
# 709 to 719 reserved for membership changes
|
||||||
|
USER_GROUP_NAME_CHANGED = 720
|
||||||
|
USER_GROUP_DESCRIPTION_CHANGED = 721
|
||||||
|
USER_GROUP_GROUP_BASED_SETTING_CHANGED = 722
|
||||||
|
|
||||||
|
|
||||||
class AbstractRealmAuditLog(models.Model):
|
class AbstractRealmAuditLog(models.Model):
|
||||||
"""Defines fields common to RealmAuditLog and RemoteRealmAuditLog."""
|
"""Defines fields common to RealmAuditLog and RemoteRealmAuditLog."""
|
||||||
|
@ -114,18 +127,6 @@ class AbstractRealmAuditLog(models.Model):
|
||||||
extra_data = models.JSONField(default=dict, encoder=DjangoJSONEncoder)
|
extra_data = models.JSONField(default=dict, encoder=DjangoJSONEncoder)
|
||||||
|
|
||||||
# Event types
|
# Event types
|
||||||
USER_GROUP_CREATED = 701
|
|
||||||
USER_GROUP_DELETED = 702
|
|
||||||
USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED = 703
|
|
||||||
USER_GROUP_DIRECT_USER_MEMBERSHIP_REMOVED = 704
|
|
||||||
USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_ADDED = 705
|
|
||||||
USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_REMOVED = 706
|
|
||||||
USER_GROUP_DIRECT_SUPERGROUP_MEMBERSHIP_ADDED = 707
|
|
||||||
USER_GROUP_DIRECT_SUPERGROUP_MEMBERSHIP_REMOVED = 708
|
|
||||||
# 709 to 719 reserved for membership changes
|
|
||||||
USER_GROUP_NAME_CHANGED = 720
|
|
||||||
USER_GROUP_DESCRIPTION_CHANGED = 721
|
|
||||||
USER_GROUP_GROUP_BASED_SETTING_CHANGED = 722
|
|
||||||
|
|
||||||
# The following values are only for RemoteZulipServerAuditLog
|
# The following values are only for RemoteZulipServerAuditLog
|
||||||
# Values should be exactly 10000 greater than the corresponding
|
# Values should be exactly 10000 greater than the corresponding
|
||||||
|
|
|
@ -130,8 +130,8 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
event_types,
|
event_types,
|
||||||
[
|
[
|
||||||
AuditLogEventType.USER_CREATED,
|
AuditLogEventType.USER_CREATED,
|
||||||
RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
AuditLogEventType.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
||||||
RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
AuditLogEventType.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
||||||
AuditLogEventType.USER_DEACTIVATED,
|
AuditLogEventType.USER_DEACTIVATED,
|
||||||
AuditLogEventType.USER_ACTIVATED,
|
AuditLogEventType.USER_ACTIVATED,
|
||||||
AuditLogEventType.USER_DEACTIVATED,
|
AuditLogEventType.USER_DEACTIVATED,
|
||||||
|
@ -147,7 +147,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
event_time__lte=now + timedelta(minutes=60),
|
event_time__lte=now + timedelta(minutes=60),
|
||||||
):
|
):
|
||||||
if event.event_type == RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED:
|
if event.event_type == AuditLogEventType.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED:
|
||||||
self.assertDictEqual(event.extra_data, {})
|
self.assertDictEqual(event.extra_data, {})
|
||||||
modified_user_group_names.append(assert_is_not_none(event.modified_user_group).name)
|
modified_user_group_names.append(assert_is_not_none(event.modified_user_group).name)
|
||||||
continue
|
continue
|
||||||
|
@ -220,7 +220,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
]
|
]
|
||||||
user_group_modified_names = (
|
user_group_modified_names = (
|
||||||
RealmAuditLog.objects.filter(
|
RealmAuditLog.objects.filter(
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
||||||
realm=realm,
|
realm=realm,
|
||||||
modified_user=user_profile,
|
modified_user=user_profile,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
|
@ -240,7 +240,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
)
|
)
|
||||||
user_group_modified_names = (
|
user_group_modified_names = (
|
||||||
RealmAuditLog.objects.filter(
|
RealmAuditLog.objects.filter(
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_REMOVED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_USER_MEMBERSHIP_REMOVED,
|
||||||
realm=realm,
|
realm=realm,
|
||||||
modified_user=user_profile,
|
modified_user=user_profile,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
|
@ -1118,7 +1118,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
logged_system_group_ids = sorted(
|
logged_system_group_ids = sorted(
|
||||||
RealmAuditLog.objects.filter(
|
RealmAuditLog.objects.filter(
|
||||||
realm=realm,
|
realm=realm,
|
||||||
event_type=RealmAuditLog.USER_GROUP_CREATED,
|
event_type=AuditLogEventType.USER_GROUP_CREATED,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
acting_user=None,
|
acting_user=None,
|
||||||
).values_list("modified_user_group_id", flat=True)
|
).values_list("modified_user_group_id", flat=True)
|
||||||
|
@ -1128,7 +1128,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
logged_subgroup_entries = sorted(
|
logged_subgroup_entries = sorted(
|
||||||
RealmAuditLog.objects.filter(
|
RealmAuditLog.objects.filter(
|
||||||
realm=realm,
|
realm=realm,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_ADDED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_ADDED,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
acting_user=None,
|
acting_user=None,
|
||||||
).values_list("modified_user_group_id", "extra_data")
|
).values_list("modified_user_group_id", "extra_data")
|
||||||
|
@ -1136,7 +1136,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
logged_supergroup_entries = sorted(
|
logged_supergroup_entries = sorted(
|
||||||
RealmAuditLog.objects.filter(
|
RealmAuditLog.objects.filter(
|
||||||
realm=realm,
|
realm=realm,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_SUPERGROUP_MEMBERSHIP_ADDED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_SUPERGROUP_MEMBERSHIP_ADDED,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
acting_user=None,
|
acting_user=None,
|
||||||
).values_list("modified_user_group_id", "extra_data")
|
).values_list("modified_user_group_id", "extra_data")
|
||||||
|
@ -1180,7 +1180,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
acting_user=hamlet,
|
acting_user=hamlet,
|
||||||
realm=hamlet.realm,
|
realm=hamlet.realm,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
event_type=RealmAuditLog.USER_GROUP_CREATED,
|
event_type=AuditLogEventType.USER_GROUP_CREATED,
|
||||||
)
|
)
|
||||||
self.assert_length(audit_log_entries, 1)
|
self.assert_length(audit_log_entries, 1)
|
||||||
self.assertIsNone(audit_log_entries[0].modified_user)
|
self.assertIsNone(audit_log_entries[0].modified_user)
|
||||||
|
@ -1190,7 +1190,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
acting_user=hamlet,
|
acting_user=hamlet,
|
||||||
realm=hamlet.realm,
|
realm=hamlet.realm,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
||||||
)
|
)
|
||||||
self.assert_length(audit_log_entries, 2)
|
self.assert_length(audit_log_entries, 2)
|
||||||
self.assertEqual(audit_log_entries[0].modified_user, hamlet)
|
self.assertEqual(audit_log_entries[0].modified_user, hamlet)
|
||||||
|
@ -1208,7 +1208,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
realm=hamlet.realm,
|
realm=hamlet.realm,
|
||||||
modified_user_group=user_group,
|
modified_user_group=user_group,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
||||||
)
|
)
|
||||||
self.assert_length(audit_log_entries, 2)
|
self.assert_length(audit_log_entries, 2)
|
||||||
self.assertEqual(audit_log_entries[0].modified_user, hamlet)
|
self.assertEqual(audit_log_entries[0].modified_user, hamlet)
|
||||||
|
@ -1220,7 +1220,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
realm=hamlet.realm,
|
realm=hamlet.realm,
|
||||||
modified_user_group=user_group,
|
modified_user_group=user_group,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_REMOVED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_USER_MEMBERSHIP_REMOVED,
|
||||||
)
|
)
|
||||||
self.assert_length(audit_log_entries, 1)
|
self.assert_length(audit_log_entries, 1)
|
||||||
self.assertEqual(audit_log_entries[0].modified_user, hamlet)
|
self.assertEqual(audit_log_entries[0].modified_user, hamlet)
|
||||||
|
@ -1239,7 +1239,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
audit_log_entry = RealmAuditLog.objects.get(
|
audit_log_entry = RealmAuditLog.objects.get(
|
||||||
realm=hamlet.realm,
|
realm=hamlet.realm,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_ADDED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_ADDED,
|
||||||
)
|
)
|
||||||
self.assertEqual(audit_log_entry.modified_user_group, user_group)
|
self.assertEqual(audit_log_entry.modified_user_group, user_group)
|
||||||
self.assertEqual(audit_log_entry.acting_user, hamlet)
|
self.assertEqual(audit_log_entry.acting_user, hamlet)
|
||||||
|
@ -1250,7 +1250,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
audit_log_entries = RealmAuditLog.objects.filter(
|
audit_log_entries = RealmAuditLog.objects.filter(
|
||||||
realm=hamlet.realm,
|
realm=hamlet.realm,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_SUPERGROUP_MEMBERSHIP_ADDED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_SUPERGROUP_MEMBERSHIP_ADDED,
|
||||||
).order_by("id")
|
).order_by("id")
|
||||||
self.assert_length(audit_log_entries, 3)
|
self.assert_length(audit_log_entries, 3)
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
|
@ -1265,7 +1265,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
audit_log_entry = RealmAuditLog.objects.get(
|
audit_log_entry = RealmAuditLog.objects.get(
|
||||||
realm=hamlet.realm,
|
realm=hamlet.realm,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_REMOVED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_REMOVED,
|
||||||
)
|
)
|
||||||
self.assertEqual(audit_log_entry.modified_user_group, user_group)
|
self.assertEqual(audit_log_entry.modified_user_group, user_group)
|
||||||
self.assertEqual(audit_log_entry.acting_user, hamlet)
|
self.assertEqual(audit_log_entry.acting_user, hamlet)
|
||||||
|
@ -1276,7 +1276,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
audit_log_entries = RealmAuditLog.objects.filter(
|
audit_log_entries = RealmAuditLog.objects.filter(
|
||||||
realm=hamlet.realm,
|
realm=hamlet.realm,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_SUPERGROUP_MEMBERSHIP_REMOVED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_SUPERGROUP_MEMBERSHIP_REMOVED,
|
||||||
).order_by("id")
|
).order_by("id")
|
||||||
self.assert_length(audit_log_entries, 2)
|
self.assert_length(audit_log_entries, 2)
|
||||||
for i in range(2):
|
for i in range(2):
|
||||||
|
@ -1301,7 +1301,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
do_update_user_group_name(user_group, "bar", acting_user=hamlet)
|
do_update_user_group_name(user_group, "bar", acting_user=hamlet)
|
||||||
audit_log_entries = RealmAuditLog.objects.filter(
|
audit_log_entries = RealmAuditLog.objects.filter(
|
||||||
realm=hamlet.realm,
|
realm=hamlet.realm,
|
||||||
event_type=RealmAuditLog.USER_GROUP_NAME_CHANGED,
|
event_type=AuditLogEventType.USER_GROUP_NAME_CHANGED,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
)
|
)
|
||||||
self.assert_length(audit_log_entries, 1)
|
self.assert_length(audit_log_entries, 1)
|
||||||
|
@ -1316,7 +1316,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
do_update_user_group_description(user_group, "Foo", acting_user=hamlet)
|
do_update_user_group_description(user_group, "Foo", acting_user=hamlet)
|
||||||
audit_log_entries = RealmAuditLog.objects.filter(
|
audit_log_entries = RealmAuditLog.objects.filter(
|
||||||
realm=hamlet.realm,
|
realm=hamlet.realm,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DESCRIPTION_CHANGED,
|
event_type=AuditLogEventType.USER_GROUP_DESCRIPTION_CHANGED,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
)
|
)
|
||||||
self.assert_length(audit_log_entries, 1)
|
self.assert_length(audit_log_entries, 1)
|
||||||
|
@ -1341,7 +1341,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
acting_user=None,
|
acting_user=None,
|
||||||
)
|
)
|
||||||
audit_log_entries = RealmAuditLog.objects.filter(
|
audit_log_entries = RealmAuditLog.objects.filter(
|
||||||
event_type=RealmAuditLog.USER_GROUP_GROUP_BASED_SETTING_CHANGED,
|
event_type=AuditLogEventType.USER_GROUP_GROUP_BASED_SETTING_CHANGED,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
)
|
)
|
||||||
self.assert_length(audit_log_entries, 1)
|
self.assert_length(audit_log_entries, 1)
|
||||||
|
@ -1370,7 +1370,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
acting_user=None,
|
acting_user=None,
|
||||||
)
|
)
|
||||||
audit_log_entries = RealmAuditLog.objects.filter(
|
audit_log_entries = RealmAuditLog.objects.filter(
|
||||||
event_type=RealmAuditLog.USER_GROUP_GROUP_BASED_SETTING_CHANGED,
|
event_type=AuditLogEventType.USER_GROUP_GROUP_BASED_SETTING_CHANGED,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
)
|
)
|
||||||
self.assert_length(audit_log_entries, 1)
|
self.assert_length(audit_log_entries, 1)
|
||||||
|
@ -1405,7 +1405,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
acting_user=None,
|
acting_user=None,
|
||||||
)
|
)
|
||||||
audit_log_entries = RealmAuditLog.objects.filter(
|
audit_log_entries = RealmAuditLog.objects.filter(
|
||||||
event_type=RealmAuditLog.USER_GROUP_GROUP_BASED_SETTING_CHANGED,
|
event_type=AuditLogEventType.USER_GROUP_GROUP_BASED_SETTING_CHANGED,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
)
|
)
|
||||||
self.assert_length(audit_log_entries, 1)
|
self.assert_length(audit_log_entries, 1)
|
||||||
|
@ -1438,7 +1438,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
acting_user=None,
|
acting_user=None,
|
||||||
)
|
)
|
||||||
audit_log_entries = RealmAuditLog.objects.filter(
|
audit_log_entries = RealmAuditLog.objects.filter(
|
||||||
event_type=RealmAuditLog.USER_GROUP_GROUP_BASED_SETTING_CHANGED,
|
event_type=AuditLogEventType.USER_GROUP_GROUP_BASED_SETTING_CHANGED,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
)
|
)
|
||||||
self.assert_length(audit_log_entries, 1)
|
self.assert_length(audit_log_entries, 1)
|
||||||
|
|
|
@ -1920,7 +1920,7 @@ class RealmImportExportTest(ExportFile):
|
||||||
imported_realm = do_import_realm(get_output_dir(), "test-zulip-1")
|
imported_realm = do_import_realm(get_output_dir(), "test-zulip-1")
|
||||||
user_membership_logs = RealmAuditLog.objects.filter(
|
user_membership_logs = RealmAuditLog.objects.filter(
|
||||||
realm=imported_realm,
|
realm=imported_realm,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
||||||
).values_list("modified_user_id", "modified_user_group__name")
|
).values_list("modified_user_id", "modified_user_group__name")
|
||||||
logged_membership_by_user_id = defaultdict(set)
|
logged_membership_by_user_id = defaultdict(set)
|
||||||
for user_id, user_group_name in user_membership_logs:
|
for user_id, user_group_name in user_membership_logs:
|
||||||
|
|
|
@ -1360,10 +1360,10 @@ class SlackImporter(ZulipTestCase):
|
||||||
AuditLogEventType.REALM_PROPERTY_CHANGED,
|
AuditLogEventType.REALM_PROPERTY_CHANGED,
|
||||||
AuditLogEventType.REALM_CREATED,
|
AuditLogEventType.REALM_CREATED,
|
||||||
AuditLogEventType.REALM_IMPORTED,
|
AuditLogEventType.REALM_IMPORTED,
|
||||||
RealmAuditLog.USER_GROUP_CREATED,
|
AuditLogEventType.USER_GROUP_CREATED,
|
||||||
RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
AuditLogEventType.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
||||||
RealmAuditLog.USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_ADDED,
|
AuditLogEventType.USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_ADDED,
|
||||||
RealmAuditLog.USER_GROUP_DIRECT_SUPERGROUP_MEMBERSHIP_ADDED,
|
AuditLogEventType.USER_GROUP_DIRECT_SUPERGROUP_MEMBERSHIP_ADDED,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,7 @@ from zerver.models.clients import get_client
|
||||||
from zerver.models.custom_profile_fields import check_valid_user_ids
|
from zerver.models.custom_profile_fields import check_valid_user_ids
|
||||||
from zerver.models.groups import SystemGroups
|
from zerver.models.groups import SystemGroups
|
||||||
from zerver.models.prereg_users import filter_to_valid_prereg_users
|
from zerver.models.prereg_users import filter_to_valid_prereg_users
|
||||||
|
from zerver.models.realm_audit_logs import AuditLogEventType
|
||||||
from zerver.models.realms import InvalidFakeEmailDomainError, get_fake_email_domain, get_realm
|
from zerver.models.realms import InvalidFakeEmailDomainError, get_fake_email_domain, get_realm
|
||||||
from zerver.models.streams import get_stream
|
from zerver.models.streams import get_stream
|
||||||
from zerver.models.users import (
|
from zerver.models.users import (
|
||||||
|
@ -995,7 +996,7 @@ class BulkCreateUserTest(ZulipTestCase):
|
||||||
RealmAuditLog.objects.filter(
|
RealmAuditLog.objects.filter(
|
||||||
realm=realm,
|
realm=realm,
|
||||||
modified_user=bono,
|
modified_user=bono,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
).values_list("modified_user_group__name", flat=True)
|
).values_list("modified_user_group__name", flat=True)
|
||||||
)
|
)
|
||||||
|
@ -1010,7 +1011,7 @@ class BulkCreateUserTest(ZulipTestCase):
|
||||||
RealmAuditLog.objects.filter(
|
RealmAuditLog.objects.filter(
|
||||||
realm=realm,
|
realm=realm,
|
||||||
modified_user=cher,
|
modified_user=cher,
|
||||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
event_type=AuditLogEventType.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
).values_list("modified_user_group__name", flat=True)
|
).values_list("modified_user_group__name", flat=True)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue