mirror of https://github.com/zulip/zulip.git
user_groups: Update user groups on changing waiting_period_threshold.
The members of "Full members" user group are updated with change in waiting_period_threshold setting.
This commit is contained in:
parent
9345c344d7
commit
bbf4c25553
|
@ -870,16 +870,27 @@ def update_users_in_full_members_system_group(
|
|||
realm=realm, name="@role:members", is_system_group=True
|
||||
)
|
||||
|
||||
full_member_group_users = list(
|
||||
full_members_system_group.direct_members.filter(id__in=affected_user_ids).values(
|
||||
"id", "role", "date_joined"
|
||||
full_member_group_users: List[Dict[str, Union[int, datetime.datetime]]] = list()
|
||||
member_group_users: List[Dict[str, Union[int, datetime.datetime]]] = list()
|
||||
|
||||
if affected_user_ids:
|
||||
full_member_group_users = list(
|
||||
full_members_system_group.direct_members.filter(id__in=affected_user_ids).values(
|
||||
"id", "role", "date_joined"
|
||||
)
|
||||
)
|
||||
)
|
||||
member_group_users = list(
|
||||
members_system_group.direct_members.filter(id__in=affected_user_ids).values(
|
||||
"id", "role", "date_joined"
|
||||
member_group_users = list(
|
||||
members_system_group.direct_members.filter(id__in=affected_user_ids).values(
|
||||
"id", "role", "date_joined"
|
||||
)
|
||||
)
|
||||
else:
|
||||
full_member_group_users = list(
|
||||
full_members_system_group.direct_members.all().values("id", "role", "date_joined")
|
||||
)
|
||||
member_group_users = list(
|
||||
members_system_group.direct_members.all().values("id", "role", "date_joined")
|
||||
)
|
||||
)
|
||||
|
||||
def is_provisional_member(user: Dict[str, Union[int, datetime.datetime]]) -> bool:
|
||||
diff = (timezone_now() - user["date_joined"]).days
|
||||
|
@ -971,6 +982,9 @@ def do_set_realm_property(
|
|||
# TODO: Design a bulk event for this or force-reload all clients
|
||||
send_user_email_update_event(user_profile)
|
||||
|
||||
if name == "waiting_period_threshold":
|
||||
update_users_in_full_members_system_group(realm)
|
||||
|
||||
|
||||
def do_set_realm_authentication_methods(
|
||||
realm: Realm, authentication_methods: Dict[str, bool], *, acting_user: Optional[UserProfile]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import datetime
|
||||
import re
|
||||
from datetime import timedelta
|
||||
from typing import Any, Dict, List, Mapping, Union
|
||||
from unittest import mock
|
||||
|
||||
|
@ -35,6 +36,7 @@ from zerver.models import (
|
|||
ScheduledEmail,
|
||||
Stream,
|
||||
UserGroup,
|
||||
UserGroupMembership,
|
||||
UserMessage,
|
||||
UserProfile,
|
||||
get_realm,
|
||||
|
@ -906,6 +908,126 @@ class RealmTest(ZulipTestCase):
|
|||
]
|
||||
self.assertEqual(user_group_names.sort(), expected_system_group_names.sort())
|
||||
|
||||
def test_changing_waiting_period_updates_system_groups(self) -> None:
|
||||
realm = get_realm("zulip")
|
||||
members_system_group = UserGroup.objects.get(
|
||||
realm=realm, name="@role:members", is_system_group=True
|
||||
)
|
||||
full_members_system_group = UserGroup.objects.get(
|
||||
realm=realm, name="@role:fullmembers", is_system_group=True
|
||||
)
|
||||
|
||||
self.assert_length(UserGroupMembership.objects.filter(user_group=members_system_group), 6)
|
||||
self.assert_length(
|
||||
UserGroupMembership.objects.filter(user_group=full_members_system_group), 6
|
||||
)
|
||||
self.assertEqual(realm.waiting_period_threshold, 0)
|
||||
|
||||
hamlet = self.example_user("hamlet")
|
||||
othello = self.example_user("othello")
|
||||
prospero = self.example_user("prospero")
|
||||
self.assertTrue(
|
||||
UserGroupMembership.objects.filter(
|
||||
user_group=members_system_group, user_profile=hamlet
|
||||
).exists()
|
||||
)
|
||||
self.assertTrue(
|
||||
UserGroupMembership.objects.filter(
|
||||
user_group=members_system_group, user_profile=othello
|
||||
).exists()
|
||||
)
|
||||
self.assertTrue(
|
||||
UserGroupMembership.objects.filter(
|
||||
user_group=members_system_group, user_profile=prospero
|
||||
).exists()
|
||||
)
|
||||
self.assertTrue(
|
||||
UserGroupMembership.objects.filter(
|
||||
user_group=full_members_system_group, user_profile=hamlet
|
||||
).exists()
|
||||
)
|
||||
self.assertTrue(
|
||||
UserGroupMembership.objects.filter(
|
||||
user_group=full_members_system_group, user_profile=othello
|
||||
).exists()
|
||||
)
|
||||
self.assertTrue(
|
||||
UserGroupMembership.objects.filter(
|
||||
user_group=full_members_system_group, user_profile=prospero
|
||||
).exists()
|
||||
)
|
||||
|
||||
hamlet.date_joined = timezone_now() - timedelta(days=50)
|
||||
hamlet.save()
|
||||
othello.date_joined = timezone_now() - timedelta(days=75)
|
||||
othello.save()
|
||||
prospero.date_joined = timezone_now() - timedelta(days=150)
|
||||
prospero.save()
|
||||
do_set_realm_property(realm, "waiting_period_threshold", 100, acting_user=None)
|
||||
|
||||
self.assertTrue(
|
||||
UserGroupMembership.objects.filter(
|
||||
user_group=members_system_group, user_profile=hamlet
|
||||
).exists()
|
||||
)
|
||||
self.assertTrue(
|
||||
UserGroupMembership.objects.filter(
|
||||
user_group=members_system_group, user_profile=othello
|
||||
).exists()
|
||||
)
|
||||
self.assertTrue(
|
||||
UserGroupMembership.objects.filter(
|
||||
user_group=members_system_group, user_profile=prospero
|
||||
).exists()
|
||||
)
|
||||
self.assertFalse(
|
||||
UserGroupMembership.objects.filter(
|
||||
user_group=full_members_system_group, user_profile=hamlet
|
||||
).exists()
|
||||
)
|
||||
self.assertFalse(
|
||||
UserGroupMembership.objects.filter(
|
||||
user_group=full_members_system_group, user_profile=othello
|
||||
).exists()
|
||||
)
|
||||
self.assertTrue(
|
||||
UserGroupMembership.objects.filter(
|
||||
user_group=full_members_system_group, user_profile=prospero
|
||||
).exists()
|
||||
)
|
||||
|
||||
do_set_realm_property(realm, "waiting_period_threshold", 70, acting_user=None)
|
||||
self.assertTrue(
|
||||
UserGroupMembership.objects.filter(
|
||||
user_group=members_system_group, user_profile=hamlet
|
||||
).exists()
|
||||
)
|
||||
self.assertTrue(
|
||||
UserGroupMembership.objects.filter(
|
||||
user_group=members_system_group, user_profile=othello
|
||||
).exists()
|
||||
)
|
||||
self.assertTrue(
|
||||
UserGroupMembership.objects.filter(
|
||||
user_group=members_system_group, user_profile=prospero
|
||||
).exists()
|
||||
)
|
||||
self.assertFalse(
|
||||
UserGroupMembership.objects.filter(
|
||||
user_group=full_members_system_group, user_profile=hamlet
|
||||
).exists()
|
||||
)
|
||||
self.assertTrue(
|
||||
UserGroupMembership.objects.filter(
|
||||
user_group=full_members_system_group, user_profile=othello
|
||||
).exists()
|
||||
)
|
||||
self.assertTrue(
|
||||
UserGroupMembership.objects.filter(
|
||||
user_group=full_members_system_group, user_profile=prospero
|
||||
).exists()
|
||||
)
|
||||
|
||||
|
||||
class RealmAPITest(ZulipTestCase):
|
||||
def setUp(self) -> None:
|
||||
|
|
Loading…
Reference in New Issue