mirror of https://github.com/zulip/zulip.git
audit_logs: Set modified_user_group field to NamedUserGroup.
This commit is contained in:
parent
6b4f665b36
commit
0ff9aacb96
|
@ -96,10 +96,10 @@ def create_user_group_in_database(
|
|||
def update_users_in_full_members_system_group(
|
||||
realm: Realm, affected_user_ids: Sequence[int] = [], *, acting_user: Optional[UserProfile]
|
||||
) -> None:
|
||||
full_members_system_group = UserGroup.objects.get(
|
||||
full_members_system_group = NamedUserGroup.objects.get(
|
||||
realm=realm, name=SystemGroups.FULL_MEMBERS, is_system_group=True
|
||||
)
|
||||
members_system_group = UserGroup.objects.get(
|
||||
members_system_group = NamedUserGroup.objects.get(
|
||||
realm=realm, name=SystemGroups.MEMBERS, is_system_group=True
|
||||
)
|
||||
|
||||
|
|
|
@ -152,7 +152,7 @@ def bulk_create_users(
|
|||
RealmAuditLog(
|
||||
realm=realm,
|
||||
modified_user=membership.user_profile,
|
||||
modified_user_group=membership.user_group,
|
||||
modified_user_group=membership.user_group.named_user_group,
|
||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
||||
event_time=now,
|
||||
acting_user=None,
|
||||
|
|
|
@ -1803,7 +1803,7 @@ def add_users_to_system_user_groups(
|
|||
RealmAuditLog(
|
||||
realm=realm,
|
||||
modified_user=membership.user_profile,
|
||||
modified_user_group=membership.user_group,
|
||||
modified_user_group=membership.user_group.named_user_group,
|
||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_USER_MEMBERSHIP_ADDED,
|
||||
event_time=now,
|
||||
acting_user=None,
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 4.2.12 on 2024-04-17 10:39
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("zerver", "0513_copy_groups_data_to_named_user_group"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="realmauditlog",
|
||||
name="modified_user_group",
|
||||
field=models.ForeignKey(
|
||||
null=True, on_delete=django.db.models.deletion.CASCADE, to="zerver.namedusergroup"
|
||||
),
|
||||
),
|
||||
]
|
|
@ -6,7 +6,7 @@ from django.db import models
|
|||
from django.db.models import CASCADE, Q
|
||||
from typing_extensions import override
|
||||
|
||||
from zerver.models.groups import UserGroup
|
||||
from zerver.models.groups import NamedUserGroup
|
||||
from zerver.models.realms import Realm
|
||||
from zerver.models.streams import Stream
|
||||
from zerver.models.users import UserProfile
|
||||
|
@ -219,7 +219,7 @@ class RealmAuditLog(AbstractRealmAuditLog):
|
|||
on_delete=CASCADE,
|
||||
)
|
||||
modified_user_group = models.ForeignKey(
|
||||
UserGroup,
|
||||
NamedUserGroup,
|
||||
null=True,
|
||||
on_delete=CASCADE,
|
||||
)
|
||||
|
|
|
@ -1167,7 +1167,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
|||
)
|
||||
self.assert_length(audit_log_entries, 1)
|
||||
self.assertIsNone(audit_log_entries[0].modified_user)
|
||||
self.assertEqual(audit_log_entries[0].modified_user_group, user_group.usergroup_ptr)
|
||||
self.assertEqual(audit_log_entries[0].modified_user_group, user_group)
|
||||
|
||||
audit_log_entries = RealmAuditLog.objects.filter(
|
||||
acting_user=hamlet,
|
||||
|
@ -1224,7 +1224,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
|||
event_time__gte=now,
|
||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_ADDED,
|
||||
)
|
||||
self.assertEqual(audit_log_entry.modified_user_group, user_group.usergroup_ptr)
|
||||
self.assertEqual(audit_log_entry.modified_user_group, user_group)
|
||||
self.assertEqual(audit_log_entry.acting_user, hamlet)
|
||||
self.assertDictEqual(
|
||||
audit_log_entry.extra_data,
|
||||
|
@ -1237,7 +1237,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
|||
).order_by("id")
|
||||
self.assert_length(audit_log_entries, 3)
|
||||
for i in range(3):
|
||||
self.assertEqual(audit_log_entries[i].modified_user_group, subgroups[i].usergroup_ptr)
|
||||
self.assertEqual(audit_log_entries[i].modified_user_group, subgroups[i])
|
||||
self.assertEqual(audit_log_entries[i].acting_user, hamlet)
|
||||
self.assertDictEqual(
|
||||
audit_log_entries[i].extra_data,
|
||||
|
@ -1250,7 +1250,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
|||
event_time__gte=now,
|
||||
event_type=RealmAuditLog.USER_GROUP_DIRECT_SUBGROUP_MEMBERSHIP_REMOVED,
|
||||
)
|
||||
self.assertEqual(audit_log_entry.modified_user_group, user_group.usergroup_ptr)
|
||||
self.assertEqual(audit_log_entry.modified_user_group, user_group)
|
||||
self.assertEqual(audit_log_entry.acting_user, hamlet)
|
||||
self.assertDictEqual(
|
||||
audit_log_entry.extra_data,
|
||||
|
@ -1263,7 +1263,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
|||
).order_by("id")
|
||||
self.assert_length(audit_log_entries, 2)
|
||||
for i in range(2):
|
||||
self.assertEqual(audit_log_entries[i].modified_user_group, subgroups[i].usergroup_ptr)
|
||||
self.assertEqual(audit_log_entries[i].modified_user_group, subgroups[i])
|
||||
self.assertEqual(audit_log_entries[i].acting_user, hamlet)
|
||||
self.assertDictEqual(
|
||||
audit_log_entries[i].extra_data,
|
||||
|
|
|
@ -110,6 +110,7 @@ from zerver.models import (
|
|||
CustomProfileField,
|
||||
CustomProfileFieldValue,
|
||||
MultiuseInvite,
|
||||
NamedUserGroup,
|
||||
PreregistrationUser,
|
||||
Realm,
|
||||
RealmDomain,
|
||||
|
@ -7505,7 +7506,7 @@ class LDAPGroupSyncTest(ZulipTestCase):
|
|||
|
||||
self.assertTrue(UserGroup.objects.filter(realm=realm, name="cool_test_group").exists())
|
||||
|
||||
user_group = UserGroup.objects.get(realm=realm, name="cool_test_group")
|
||||
user_group = NamedUserGroup.objects.get(realm=realm, name="cool_test_group")
|
||||
|
||||
self.assertFalse(
|
||||
is_user_in_group(
|
||||
|
|
|
@ -103,10 +103,10 @@ from zerver.lib.url_encoding import append_url_query_string
|
|||
from zerver.lib.users import check_full_name, validate_user_custom_profile_field
|
||||
from zerver.models import (
|
||||
CustomProfileField,
|
||||
NamedUserGroup,
|
||||
PreregistrationRealm,
|
||||
PreregistrationUser,
|
||||
Realm,
|
||||
UserGroup,
|
||||
UserGroupMembership,
|
||||
UserProfile,
|
||||
)
|
||||
|
@ -999,7 +999,7 @@ class ZulipLDAPAuthBackendBase(ZulipAuthMixin, LDAPBackend):
|
|||
repr(existing_group_name_set_for_user),
|
||||
)
|
||||
|
||||
new_groups = UserGroup.objects.filter(
|
||||
new_groups = NamedUserGroup.objects.filter(
|
||||
name__in=intended_group_name_set_for_user.difference(
|
||||
existing_group_name_set_for_user
|
||||
),
|
||||
|
@ -1014,7 +1014,7 @@ class ZulipLDAPAuthBackendBase(ZulipAuthMixin, LDAPBackend):
|
|||
group_names_for_membership_deletion = existing_group_name_set_for_user.difference(
|
||||
intended_group_name_set_for_user
|
||||
)
|
||||
groups_for_membership_deletion = UserGroup.objects.filter(
|
||||
groups_for_membership_deletion = NamedUserGroup.objects.filter(
|
||||
name__in=group_names_for_membership_deletion, realm=user_profile.realm
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue