settings: Use `can_create_groups` to control who can create user groups.

This commit is contained in:
Shubham Padia 2024-09-12 02:54:42 +00:00 committed by Tim Abbott
parent 17276e95a1
commit a9e14a184c
6 changed files with 23 additions and 11 deletions

View File

@ -483,6 +483,7 @@ const dropdown_widget_map = new Map<string, DropdownWidget | null>([
["can_remove_subscribers_group", null],
["realm_can_access_all_users_group", null],
["can_mention_group", null],
["realm_can_create_groups", null],
["realm_can_create_public_channel_group", null],
["realm_can_create_private_channel_group", null],
["realm_can_create_web_public_channel_group", null],
@ -802,6 +803,7 @@ export function check_realm_settings_property_changed(elem: HTMLElement): boolea
case "realm_default_code_block_language":
case "realm_create_multiuse_invite_group":
case "realm_can_access_all_users_group":
case "realm_can_create_groups":
case "realm_can_create_public_channel_group":
case "realm_can_create_private_channel_group":
case "realm_can_create_web_public_channel_group":
@ -1037,6 +1039,7 @@ export function populate_data_for_realm_settings_request(
}
const realm_group_settings_using_new_api_format = new Set([
"can_create_groups",
"can_create_private_channel_group",
"can_create_public_channel_group",
"can_create_web_public_channel_group",

View File

@ -220,7 +220,14 @@ export function can_edit_user_group(group_id: number): boolean {
}
export function user_can_create_user_groups(): boolean {
return user_has_permission(realm.realm_user_group_edit_policy);
if (page_params.is_spectator) {
return false;
}
return user_has_permission_for_group_setting(
realm.realm_can_create_groups,
"can_create_groups",
"realm",
);
}
export function user_can_add_custom_emoji(): boolean {

View File

@ -511,6 +511,7 @@ export function discard_realm_property_element_changes(elem) {
case "realm_direct_message_initiator_group":
case "realm_direct_message_permission_group":
case "realm_can_access_all_users_group":
case "realm_can_create_groups":
case "realm_can_create_public_channel_group":
case "realm_can_create_private_channel_group":
case "realm_can_create_web_public_channel_group":
@ -844,11 +845,6 @@ export function set_up_dropdown_widget_for_realm_group_settings() {
dropdown_list_item_click_callback = check_disable_message_delete_limit_setting_dropdown;
}
if (setting_name === "can_create_groups") {
// Temporarily skip this setting until further commits
// where this setting will be ready to use.
continue;
}
set_up_dropdown_widget(
"realm_" + setting_name,
get_setting_options,

View File

@ -285,6 +285,7 @@ const realm_schema = z.object({
realm_bot_creation_policy: z.number(),
realm_bot_domain: z.string(),
realm_can_access_all_users_group: z.number(),
realm_can_create_groups: z.number(),
realm_can_create_public_channel_group: z.number(),
realm_can_create_private_channel_group: z.number(),
realm_can_create_web_public_channel_group: z.number(),

View File

@ -338,6 +338,12 @@
</select>
</div>
{{> ../dropdown_widget_with_label
widget_name="realm_can_create_groups"
label=(t 'Who can create user groups')
value_type="number"
is_setting_disabled=(not is_owner)}}
<div class="input-group">
<label for="realm_user_group_edit_policy" class="settings-field-label">{{t "Who can create and manage user groups" }}</label>
<select name="realm_user_group_edit_policy" id="id_realm_user_group_edit_policy" class="prop-element settings_select bootstrap-focus-style" data-setting-widget-type="number">

View File

@ -158,11 +158,6 @@ test_policy(
"realm_move_messages_between_streams_policy",
settings_data.user_can_move_messages_between_streams,
);
test_policy(
"user_can_create_user_groups",
"realm_user_group_edit_policy",
settings_data.user_can_create_user_groups,
);
test_policy(
"user_can_edit_all_user_groups",
"realm_user_group_edit_policy",
@ -506,6 +501,10 @@ run_test("user_can_create_public_streams", () => {
);
});
run_test("user_can_create_user_groups", () => {
test_realm_group_settings("realm_can_create_groups", settings_data.user_can_create_user_groups);
});
run_test("user_can_create_private_streams", () => {
test_realm_group_settings(
"realm_can_create_private_channel_group",