diff --git a/web/src/settings_components.ts b/web/src/settings_components.ts index 8afbc45c6a..3fdd953264 100644 --- a/web/src/settings_components.ts +++ b/web/src/settings_components.ts @@ -484,6 +484,7 @@ const dropdown_widget_map = new Map([ ["realm_can_access_all_users_group", null], ["can_mention_group", null], ["realm_can_create_groups", null], + ["realm_can_manage_all_groups", null], ["realm_can_create_public_channel_group", null], ["realm_can_create_private_channel_group", null], ["realm_can_create_web_public_channel_group", null], @@ -804,6 +805,7 @@ export function check_realm_settings_property_changed(elem: HTMLElement): boolea case "realm_create_multiuse_invite_group": case "realm_can_access_all_users_group": case "realm_can_create_groups": + case "realm_can_manage_all_groups": case "realm_can_create_public_channel_group": case "realm_can_create_private_channel_group": case "realm_can_create_web_public_channel_group": @@ -1040,6 +1042,7 @@ export function populate_data_for_realm_settings_request( const realm_group_settings_using_new_api_format = new Set([ "can_create_groups", + "can_manage_all_groups", "can_create_private_channel_group", "can_create_public_channel_group", "can_create_web_public_channel_group", diff --git a/web/src/settings_data.ts b/web/src/settings_data.ts index 6e2f024b83..c0ff5862af 100644 --- a/web/src/settings_data.ts +++ b/web/src/settings_data.ts @@ -189,7 +189,14 @@ export function user_can_move_messages_between_streams(): boolean { } export function user_can_edit_all_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_manage_all_groups, + "can_manage_all_groups", + "realm", + ); } export function can_edit_user_group(group_id: number): boolean { @@ -199,6 +206,16 @@ export function can_edit_user_group(group_id: number): boolean { let can_edit_all_user_groups = user_can_edit_all_user_groups(); + const group = user_groups.get_user_group_from_id(group_id); + + // This is a temporary exception and this should be removed as soon + // as `group_creator` is set as a default for `can_manage_group` + // property of user groups. See this topic for more details: + // https://chat.zulip.org/#narrow/stream/3-backend/topic/Group.20creation.20-.20who.20can.20change.20the.20setting.2E/near/1943861 + if (group.creator_id && group.creator_id === current_user.user_id) { + return true; + } + if ( !current_user.is_admin && !current_user.is_moderator && @@ -211,7 +228,6 @@ export function can_edit_user_group(group_id: number): boolean { return true; } - const group = user_groups.get_user_group_from_id(group_id); return user_has_permission_for_group_setting( group.can_manage_group, "can_manage_group", diff --git a/web/src/settings_org.js b/web/src/settings_org.js index 846ac1c2df..d50604faf8 100644 --- a/web/src/settings_org.js +++ b/web/src/settings_org.js @@ -512,6 +512,7 @@ export function discard_realm_property_element_changes(elem) { case "realm_direct_message_permission_group": case "realm_can_access_all_users_group": case "realm_can_create_groups": + case "realm_can_manage_all_groups": case "realm_can_create_public_channel_group": case "realm_can_create_private_channel_group": case "realm_can_create_web_public_channel_group": @@ -845,12 +846,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_manage_all_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, diff --git a/web/src/state_data.ts b/web/src/state_data.ts index 7948c1c201..fbcb11530f 100644 --- a/web/src/state_data.ts +++ b/web/src/state_data.ts @@ -286,6 +286,7 @@ const realm_schema = z.object({ realm_bot_domain: z.string(), realm_can_access_all_users_group: z.number(), realm_can_create_groups: z.number(), + realm_can_manage_all_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(), diff --git a/web/src/user_group_edit_members.ts b/web/src/user_group_edit_members.ts index b6bcdfc00e..981e1da013 100644 --- a/web/src/user_group_edit_members.ts +++ b/web/src/user_group_edit_members.ts @@ -356,7 +356,7 @@ function remove_member({ }); } - if (people.is_my_user_id(target_user_id) && !current_user.is_admin) { + if (people.is_my_user_id(target_user_id) && !settings_data.can_edit_user_group(group_id)) { const html_body = render_leave_user_group_modal({ message: $t({ defaultMessage: "Once you leave this group, you will not be able to rejoin.", diff --git a/web/templates/settings/organization_permissions_admin.hbs b/web/templates/settings/organization_permissions_admin.hbs index 6e0003d918..f59d612a08 100644 --- a/web/templates/settings/organization_permissions_admin.hbs +++ b/web/templates/settings/organization_permissions_admin.hbs @@ -344,6 +344,12 @@ value_type="number" is_setting_disabled=(not is_owner)}} + {{> ../dropdown_widget_with_label + widget_name="realm_can_manage_all_groups" + label=(t 'Who can manage user groups') + value_type="number" + is_setting_disabled=(not is_owner)}} +