FIX: Don't display staff-only options to non-staff in group member bulk menu (#19907)

In the group member bulk edit menu we are displaying staff-only options
to non-staff. The requests are blocked by the back-end, so there is no
harm other than to the user experience.

Notably the individual user edit menu is correctly filtering out
unavailable options. This change brings the bulk edit menu in line with
that.
This commit is contained in:
Ted Johansson 2023-01-20 11:16:04 +08:00 committed by GitHub
parent 019ec74076
commit 90d452ab6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 18 deletions

View File

@ -39,6 +39,7 @@ export default DropdownSelectBoxComponent.extend({
});
}
if (this.currentUser.staff) {
if (this.bulkSelection.some((m) => !m.primary)) {
items.push({
id: "setPrimary",
@ -56,6 +57,7 @@ export default DropdownSelectBoxComponent.extend({
icon: "id-card",
});
}
}
return items;
}),

View File

@ -72,10 +72,9 @@ acceptance("Group Members", function (needs) {
);
});
test("Shows bulk actions", async function (assert) {
test("Shows bulk actions as an admin user", async function (assert) {
await visit("/g/discourse");
assert.ok(exists("button.bulk-select"));
await click("button.bulk-select");
await click(queryAll("input.bulk-select")[0]);
@ -83,7 +82,50 @@ acceptance("Group Members", function (needs) {
const memberDropdown = selectKit(".bulk-group-member-dropdown");
await memberDropdown.expand();
await memberDropdown.selectRowByValue("makeOwners");
assert.ok(
exists('[data-value="removeMembers"]'),
"it includes remove member option"
);
assert.ok(
exists('[data-value="makeOwners"]'),
"it includes make owners option"
);
assert.ok(
exists('[data-value="setPrimary"]'),
"it includes set primary option"
);
});
test("Shows bulk actions as a group owner", async function (assert) {
updateCurrentUser({ moderator: false, admin: false });
await visit("/g/discourse");
await click("button.bulk-select");
await click(queryAll("input.bulk-select")[0]);
await click(queryAll("input.bulk-select")[1]);
const memberDropdown = selectKit(".bulk-group-member-dropdown");
await memberDropdown.expand();
assert.ok(
exists('[data-value="removeMembers"]'),
"it includes remove member option"
);
assert.ok(
exists('[data-value="makeOwners"]'),
"it includes make owners option"
);
assert.notOk(
exists('[data-value="setPrimary"]'),
"it does not include set primary (staff only) option"
);
});
test("Bulk actions - Menu, Select all and Clear all buttons", async function (assert) {