composebox_typeahead: Hide user groups from mention typeahead.

This commit adds code to hide the user groups which a user is
not allowed to mention from the mention typeahead.

Fixes a part of #25927.
This commit is contained in:
Sahil Batra
2023-06-15 22:04:55 +05:30
committed by Tim Abbott
parent 767c2ebbe4
commit 632191b8c4
3 changed files with 52 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
import * as blueslip from "./blueslip";
import {FoldDict} from "./fold_dict";
import * as group_permission_settings from "./group_permission_settings";
import {page_params} from "./page_params";
import * as settings_config from "./settings_config";
import type {User, UserGroupUpdateEvent} from "./types";
@@ -88,6 +89,21 @@ export function get_realm_user_groups(): UserGroup[] {
return user_groups.filter((group) => !group.is_system_group);
}
export function get_user_groups_allowed_to_mention(): UserGroup[] {
if (page_params.user_id === undefined) {
return [];
}
const user_groups = get_realm_user_groups();
return user_groups.filter((group) => {
const can_mention_group_id = group.can_mention_group_id;
return (
page_params.user_id !== undefined &&
is_user_in_group(can_mention_group_id, page_params.user_id)
);
});
}
export function is_direct_member_of(user_id: number, user_group_id: number): boolean {
const user_group = user_group_by_id_dict.get(user_group_id);
if (user_group === undefined) {