user_groups: Allow adding users who are members of subgroups.

This commit updates the code, which checks if user is member of
the group before adding them to the group, to consider only
direct members and now allows members of subgroups to be added
as direct members of the group.
This commit is contained in:
Sahil Batra
2024-10-16 14:47:58 +05:30
committed by Tim Abbott
parent aa2c7bf1d1
commit a3b7d956bc
3 changed files with 23 additions and 3 deletions

View File

@@ -311,7 +311,11 @@ export function get_recursive_group_members(target_user_group: UserGroup): Set<n
return members;
}
export function is_user_in_group(user_group_id: number, user_id: number): boolean {
export function is_user_in_group(
user_group_id: number,
user_id: number,
direct_member_only = false,
): boolean {
const user_group = user_group_by_id_dict.get(user_group_id);
if (user_group === undefined) {
blueslip.error("Could not find user group", {user_group_id});
@@ -321,6 +325,10 @@ export function is_user_in_group(user_group_id: number, user_id: number): boolea
return true;
}
if (direct_member_only) {
return false;
}
const subgroup_ids = get_recursive_subgroups(user_group);
if (subgroup_ids === undefined) {
return false;