user_groups: Rename get_user_groups to get_direct_user_groups.

This is a prep commit for new permissions model in which a user
group would be able to have a subgroup.

This commit renames get_user_groups to get_direct_user_groups
to specify that the function is used only to fetch the direct
groups that user is part of and not subgroups of the direct
group.

Extracted this commit from #19866.

Co-authored-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Sahil Batra 2021-10-09 23:23:03 +05:30 committed by Tim Abbott
parent 82af2d3db5
commit 07e2ecf221
2 changed files with 4 additions and 4 deletions

View File

@ -54,7 +54,7 @@ def user_groups_in_realm_serialized(realm: Realm) -> List[Dict[str, Any]]:
return sorted(group_dicts.values(), key=lambda group_dict: group_dict["id"])
def get_user_groups(user_profile: UserProfile) -> List[UserGroup]:
def get_direct_user_groups(user_profile: UserProfile) -> List[UserGroup]:
return list(user_profile.usergroup_set.all())

View File

@ -9,8 +9,8 @@ from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.test_helpers import most_recent_usermessage
from zerver.lib.user_groups import (
create_user_group,
get_direct_user_groups,
get_memberships_of_users,
get_user_groups,
user_groups_in_realm_serialized,
)
from zerver.models import Realm, UserGroup, UserGroupMembership, UserProfile, get_realm
@ -43,10 +43,10 @@ class UserGroupTestCase(ZulipTestCase):
self.assertEqual(user_groups[1]["description"], "")
self.assertEqual(user_groups[1]["members"], [])
def test_get_user_groups(self) -> None:
def test_get_direct_user_groups(self) -> None:
othello = self.example_user("othello")
self.create_user_group_for_test("support")
user_groups = get_user_groups(othello)
user_groups = get_direct_user_groups(othello)
self.assert_length(user_groups, 1)
self.assertEqual(user_groups[0].name, "support")