user_groups: Add members to the System groups created.

This commit adds users to the appropriate system user group
based on their role. We also change the user groups when
changing role of the user.

We also add migration to add existing users to the appropriate
user groups.

This commit adds update_users_in_full_members_system_group which
is currently used to update the full members group on changing
role of a user. This function will be modified in next commit such
that it can be used to update full members group on changing
waiting_period_threshold setting of realm.
This commit is contained in:
Sahil Batra
2021-08-12 15:45:06 +05:30
committed by Tim Abbott
parent c33ba4ed6e
commit 9345c344d7
10 changed files with 382 additions and 40 deletions

View File

@@ -73,6 +73,7 @@ from zerver.lib.test_console_output import (
tee_stdout_and_find_extra_console_output,
)
from zerver.lib.test_helpers import find_key_by_email, instrument_url
from zerver.lib.user_groups import get_system_user_group_for_user
from zerver.lib.users import get_api_key
from zerver.lib.validator import check_string
from zerver.lib.webhooks.common import (
@@ -89,6 +90,7 @@ from zerver.models import (
Recipient,
Stream,
Subscription,
UserGroupMembership,
UserMessage,
UserProfile,
UserStatus,
@@ -1519,6 +1521,12 @@ Output:
if count == 0:
raise AssertionError("test is meaningless without any pertinent rows")
def check_user_added_in_system_group(self, user: UserProfile) -> None:
user_group = get_system_user_group_for_user(user)
self.assertTrue(
UserGroupMembership.objects.filter(user_profile=user, user_group=user_group).exists()
)
class WebhookTestCase(ZulipTestCase):
"""Shared test class for all incoming webhooks tests.