diff --git a/frontend_tests/node_tests/user_groups.js b/frontend_tests/node_tests/user_groups.js index debff1dea2..a1bb29688d 100644 --- a/frontend_tests/node_tests/user_groups.js +++ b/frontend_tests/node_tests/user_groups.js @@ -299,11 +299,22 @@ run_test("get_realm_user_groups_for_dropdown_list_widget", () => { is_system_group: true, direct_subgroup_ids: new Set([5]), }; + const students = { + description: "Students group", + name: "Students", + id: 8, + members: new Set([1, 2]), + is_system_group: false, + direct_subgroup_ids: new Set([4, 5]), + }; - assert.throws(() => user_groups.get_realm_user_groups_for_dropdown_list_widget(false, false), { - name: "Error", - message: "Unknown group name: @role:internet", - }); + assert.throws( + () => user_groups.get_realm_user_groups_for_dropdown_list_widget(true, false, false), + { + name: "Error", + message: "Unknown group name: @role:internet", + }, + ); let expected_groups_list = [ {name: "translated: Admins, moderators, members and guests", value: "5"}, @@ -315,11 +326,20 @@ run_test("get_realm_user_groups_for_dropdown_list_widget", () => { ]; user_groups.initialize({ - realm_user_groups: [owners, admins, moderators, members, everyone, full_members, internet], + realm_user_groups: [ + owners, + admins, + moderators, + members, + everyone, + full_members, + internet, + students, + ], }); assert.deepEqual( - user_groups.get_realm_user_groups_for_dropdown_list_widget(true, false), + user_groups.get_realm_user_groups_for_dropdown_list_widget(true, true, false), expected_groups_list, ); @@ -332,7 +352,7 @@ run_test("get_realm_user_groups_for_dropdown_list_widget", () => { {name: "translated: Admins", value: "2"}, ]; assert.deepEqual( - user_groups.get_realm_user_groups_for_dropdown_list_widget(false, true), + user_groups.get_realm_user_groups_for_dropdown_list_widget(true, false, true), expected_groups_list, ); @@ -344,7 +364,7 @@ run_test("get_realm_user_groups_for_dropdown_list_widget", () => { {name: "translated: Admins", value: "2"}, ]; assert.deepEqual( - user_groups.get_realm_user_groups_for_dropdown_list_widget(true, true), + user_groups.get_realm_user_groups_for_dropdown_list_widget(true, true, true), expected_groups_list, ); @@ -358,7 +378,20 @@ run_test("get_realm_user_groups_for_dropdown_list_widget", () => { {name: "translated: Owners", value: "1"}, ]; assert.deepEqual( - user_groups.get_realm_user_groups_for_dropdown_list_widget(false, false), + user_groups.get_realm_user_groups_for_dropdown_list_widget(true, false, false), + expected_groups_list, + ); + + expected_groups_list = [ + {name: "translated: Admins, moderators, members and guests", value: "5"}, + {name: "translated: Admins, moderators and members", value: "4"}, + {name: "translated: Admins, moderators and full members", value: "6"}, + {name: "translated: Admins and moderators", value: "3"}, + {name: "translated: Admins", value: "2"}, + {name: "Students", value: "8"}, + ]; + assert.deepEqual( + user_groups.get_realm_user_groups_for_dropdown_list_widget(false, true, true), expected_groups_list, ); }); diff --git a/static/js/stream_edit.js b/static/js/stream_edit.js index 7d7b3dac57..3d30e9e41b 100644 --- a/static/js/stream_edit.js +++ b/static/js/stream_edit.js @@ -206,7 +206,7 @@ export function show_settings_for(node) { const opts = { widget_name: "can_remove_subscribers_group_id", - data: user_groups.get_realm_user_groups_for_dropdown_list_widget(true, true), + data: user_groups.get_realm_user_groups_for_dropdown_list_widget(true, true, true), default_text: $t({defaultMessage: "No user groups"}), include_current_item: false, value: sub.can_remove_subscribers_group_id, diff --git a/static/js/stream_settings_ui.js b/static/js/stream_settings_ui.js index 43133150d1..ee3090c395 100644 --- a/static/js/stream_settings_ui.js +++ b/static/js/stream_settings_ui.js @@ -630,7 +630,7 @@ export function setup_page(callback) { const opts = { widget_name: "new_stream_can_remove_subscribers_group_id", - data: user_groups.get_realm_user_groups_for_dropdown_list_widget(true, true), + data: user_groups.get_realm_user_groups_for_dropdown_list_widget(true, true, true), default_text: $t({defaultMessage: "No user groups"}), include_current_item: false, value: user_groups.get_user_group_from_name("@role:administrators").id, diff --git a/static/js/user_groups.ts b/static/js/user_groups.ts index 14c3811103..59e0f6dd04 100644 --- a/static/js/user_groups.ts +++ b/static/js/user_groups.ts @@ -203,10 +203,11 @@ export function is_user_in_group(user_group_id: number, user_id: number): boolea } export function get_realm_user_groups_for_dropdown_list_widget( + require_system_group: boolean, exclude_internet_group: boolean, exclude_owners_group: boolean, ): UserGroupForDropdownListWidget[] { - return settings_config.system_user_groups_list + const system_user_groups = settings_config.system_user_groups_list .filter((group) => { if (exclude_internet_group && group.name === "@role:internet") { return false; @@ -228,4 +229,15 @@ export function get_realm_user_groups_for_dropdown_list_widget( value: user_group.id.toString(), }; }); + + if (require_system_group) { + return system_user_groups; + } + + const user_groups_excluding_system_groups = get_realm_user_groups().map((group) => ({ + name: group.name, + value: group.id.toString(), + })); + + return system_user_groups.concat(user_groups_excluding_system_groups); }