groups: Fix queries to get members and sugroups for user group objects.

This commit fixes the queries to get members and subgroups for
user group objects returned by user_groups_in_realm_serialized
to not include the UserGroup objects which are not linked to a
NamedUserGroup object, since the function only returns data for
NamedUserGroup objects.
This commit is contained in:
Sahil Batra 2024-05-02 09:16:09 +05:30 committed by Tim Abbott
parent e0f634ae11
commit ce9f4231c7
1 changed files with 8 additions and 4 deletions

View File

@ -269,14 +269,18 @@ def user_groups_in_realm_serialized(realm: Realm) -> List[UserGroupDict]:
can_mention_group=user_group.can_mention_group_id,
)
membership = UserGroupMembership.objects.filter(user_group__realm=realm).values_list(
"user_group_id", "user_profile_id"
membership = (
UserGroupMembership.objects.filter(user_group__realm=realm)
.exclude(user_group__named_user_group=None)
.values_list("user_group_id", "user_profile_id")
)
for user_group_id, user_profile_id in membership:
group_dicts[user_group_id]["members"].append(user_profile_id)
group_membership = GroupGroupMembership.objects.filter(subgroup__realm=realm).values_list(
"subgroup_id", "supergroup_id"
group_membership = (
GroupGroupMembership.objects.filter(subgroup__realm=realm)
.exclude(supergroup__named_user_group=None)
.values_list("subgroup_id", "supergroup_id")
)
for subgroup_id, supergroup_id in group_membership:
group_dicts[supergroup_id]["direct_subgroup_ids"].append(subgroup_id)