mirror of https://github.com/zulip/zulip.git
user_groups: Add require_system_group parameter.
This commit adds require_system_group parameter to get_realm_user_groups_for_dropdown_list_widget. We currently pass this parameter as "true" always, but this will be needed in future when we will allow to set groups other than system groups in settings.
This commit is contained in:
parent
3e7de4cc64
commit
416c7c2199
|
@ -299,11 +299,22 @@ run_test("get_realm_user_groups_for_dropdown_list_widget", () => {
|
||||||
is_system_group: true,
|
is_system_group: true,
|
||||||
direct_subgroup_ids: new Set([5]),
|
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), {
|
assert.throws(
|
||||||
|
() => user_groups.get_realm_user_groups_for_dropdown_list_widget(true, false, false),
|
||||||
|
{
|
||||||
name: "Error",
|
name: "Error",
|
||||||
message: "Unknown group name: @role:internet",
|
message: "Unknown group name: @role:internet",
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
let expected_groups_list = [
|
let expected_groups_list = [
|
||||||
{name: "translated: Admins, moderators, members and guests", value: "5"},
|
{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({
|
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(
|
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,
|
expected_groups_list,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -332,7 +352,7 @@ run_test("get_realm_user_groups_for_dropdown_list_widget", () => {
|
||||||
{name: "translated: Admins", value: "2"},
|
{name: "translated: Admins", value: "2"},
|
||||||
];
|
];
|
||||||
assert.deepEqual(
|
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,
|
expected_groups_list,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -344,7 +364,7 @@ run_test("get_realm_user_groups_for_dropdown_list_widget", () => {
|
||||||
{name: "translated: Admins", value: "2"},
|
{name: "translated: Admins", value: "2"},
|
||||||
];
|
];
|
||||||
assert.deepEqual(
|
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,
|
expected_groups_list,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -358,7 +378,20 @@ run_test("get_realm_user_groups_for_dropdown_list_widget", () => {
|
||||||
{name: "translated: Owners", value: "1"},
|
{name: "translated: Owners", value: "1"},
|
||||||
];
|
];
|
||||||
assert.deepEqual(
|
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,
|
expected_groups_list,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -206,7 +206,7 @@ export function show_settings_for(node) {
|
||||||
|
|
||||||
const opts = {
|
const opts = {
|
||||||
widget_name: "can_remove_subscribers_group_id",
|
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"}),
|
default_text: $t({defaultMessage: "No user groups"}),
|
||||||
include_current_item: false,
|
include_current_item: false,
|
||||||
value: sub.can_remove_subscribers_group_id,
|
value: sub.can_remove_subscribers_group_id,
|
||||||
|
|
|
@ -630,7 +630,7 @@ export function setup_page(callback) {
|
||||||
|
|
||||||
const opts = {
|
const opts = {
|
||||||
widget_name: "new_stream_can_remove_subscribers_group_id",
|
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"}),
|
default_text: $t({defaultMessage: "No user groups"}),
|
||||||
include_current_item: false,
|
include_current_item: false,
|
||||||
value: user_groups.get_user_group_from_name("@role:administrators").id,
|
value: user_groups.get_user_group_from_name("@role:administrators").id,
|
||||||
|
|
|
@ -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(
|
export function get_realm_user_groups_for_dropdown_list_widget(
|
||||||
|
require_system_group: boolean,
|
||||||
exclude_internet_group: boolean,
|
exclude_internet_group: boolean,
|
||||||
exclude_owners_group: boolean,
|
exclude_owners_group: boolean,
|
||||||
): UserGroupForDropdownListWidget[] {
|
): UserGroupForDropdownListWidget[] {
|
||||||
return settings_config.system_user_groups_list
|
const system_user_groups = settings_config.system_user_groups_list
|
||||||
.filter((group) => {
|
.filter((group) => {
|
||||||
if (exclude_internet_group && group.name === "@role:internet") {
|
if (exclude_internet_group && group.name === "@role:internet") {
|
||||||
return false;
|
return false;
|
||||||
|
@ -228,4 +229,15 @@ export function get_realm_user_groups_for_dropdown_list_widget(
|
||||||
value: user_group.id.toString(),
|
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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue