mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
group-settings: Move functions used for group settings.
This commit moves get_realm_user_groups_for_setting and get_realm_user_groups_for_dropdown_list_widget functions from user_groups.ts to group_permission_settings.ts. This change is needed to avoid import cycles in further commits to add "Permissions" panel for groups.
This commit is contained in:
@@ -3,9 +3,7 @@ import {z} from "zod";
|
||||
|
||||
import * as blueslip from "./blueslip.ts";
|
||||
import {FoldDict} from "./fold_dict.ts";
|
||||
import * as group_permission_settings from "./group_permission_settings.ts";
|
||||
import {$t} from "./i18n.ts";
|
||||
import {page_params} from "./page_params.ts";
|
||||
import type {UserGroupUpdateEvent} from "./server_event_types.ts";
|
||||
import * as settings_config from "./settings_config.ts";
|
||||
import type {GroupPermissionSetting, GroupSettingValue, StateData} from "./state_data.ts";
|
||||
@@ -23,11 +21,6 @@ export const user_group_schema = raw_user_group_schema.extend({
|
||||
});
|
||||
export type UserGroup = z.infer<typeof user_group_schema>;
|
||||
|
||||
export type UserGroupForDropdownListWidget = {
|
||||
name: string;
|
||||
unique_id: number;
|
||||
};
|
||||
|
||||
let user_group_name_dict: FoldDict<UserGroup>;
|
||||
let user_group_by_id_dict: Map<number, UserGroup>;
|
||||
|
||||
@@ -542,7 +535,10 @@ export function is_user_in_setting_group(
|
||||
return false;
|
||||
}
|
||||
|
||||
function get_display_name_for_system_group_option(setting_name: string, name: string): string {
|
||||
export function get_display_name_for_system_group_option(
|
||||
setting_name: string,
|
||||
name: string,
|
||||
): string {
|
||||
// We use a special label for the "Nobody" system group for clarity.
|
||||
if (setting_name === "direct_message_permission_group" && name === "Nobody") {
|
||||
return $t({defaultMessage: "Direct messages disabled"});
|
||||
@@ -589,70 +585,6 @@ export function check_system_user_group_allowed_for_setting(
|
||||
return true;
|
||||
}
|
||||
|
||||
export function get_realm_user_groups_for_setting(
|
||||
setting_name: string,
|
||||
setting_type: "realm" | "stream" | "group",
|
||||
for_new_settings_ui = false,
|
||||
): UserGroup[] {
|
||||
const group_setting_config = group_permission_settings.get_group_permission_setting_config(
|
||||
setting_name,
|
||||
setting_type,
|
||||
);
|
||||
|
||||
if (group_setting_config === undefined) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const system_user_groups = settings_config.system_user_groups_list
|
||||
.filter((group) =>
|
||||
check_system_user_group_allowed_for_setting(
|
||||
group.name,
|
||||
group_setting_config,
|
||||
for_new_settings_ui,
|
||||
),
|
||||
)
|
||||
.map((group) => {
|
||||
const user_group = get_user_group_from_name(group.name);
|
||||
if (!user_group) {
|
||||
throw new Error(`Unknown group name: ${group.name}`);
|
||||
}
|
||||
return user_group;
|
||||
});
|
||||
|
||||
if (!page_params.development_environment || group_setting_config.require_system_group) {
|
||||
return system_user_groups;
|
||||
}
|
||||
|
||||
const user_groups_excluding_system_groups = get_realm_user_groups();
|
||||
|
||||
return [...system_user_groups, ...user_groups_excluding_system_groups];
|
||||
}
|
||||
|
||||
export function get_realm_user_groups_for_dropdown_list_widget(
|
||||
setting_name: string,
|
||||
setting_type: "realm" | "stream" | "group",
|
||||
): UserGroupForDropdownListWidget[] {
|
||||
const allowed_setting_groups = get_realm_user_groups_for_setting(setting_name, setting_type);
|
||||
|
||||
return allowed_setting_groups.map((group) => {
|
||||
if (!group.is_system_group) {
|
||||
return {
|
||||
name: group.name,
|
||||
unique_id: group.id,
|
||||
};
|
||||
}
|
||||
|
||||
const display_name = settings_config.system_user_groups_list.find(
|
||||
(system_group) => system_group.name === group.name,
|
||||
)!.dropdown_option_name;
|
||||
|
||||
return {
|
||||
name: get_display_name_for_system_group_option(setting_name, display_name),
|
||||
unique_id: group.id,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export function get_display_group_name(group_name: string): string {
|
||||
const group = settings_config.system_user_groups_list.find(
|
||||
(system_group) => system_group.name === group_name,
|
||||
|
||||
Reference in New Issue
Block a user