Skip to content

A platform for community discussion. Free, open, simple.

FIX: Save staff group before enabling an "everyone"-excluded change (#41344)

Régis Hanol06b35cf0b12a
diff --git a/frontend/discourse/admin/components/admin-config-areas/upcoming-change-item.gjs b/frontend/discourse/admin/components/admin-config-areas/upcoming-change-item.gjs
index 3003059dc93..d680f584618 100644
--- a/frontend/discourse/admin/components/admin-config-areas/upcoming-change-item.gjs
+++ b/frontend/discourse/admin/components/admin-config-areas/upcoming-change-item.gjs
@@ -261,16 +261,16 @@ export default class UpcomingChangeItem extends Component {
const isEnabled = newValue !== "no_one";
try {
- await this.toggleChange(isEnabled, newValue);
-
if (newValue === this.staffGroupName) {
this.groupsChanged(this.staffGroupName);
- } else if (newValue === "everyone" || newValue === "no_one") {
+ await this.saveGroups({ silenceToast: true });
+ await this.toggleChange(isEnabled, newValue);
+ } else {
+ await this.toggleChange(isEnabled, newValue);
this.groupsChanged("");
+ await this.saveGroups({ silenceToast: true });
}
- await this.saveGroups({ silenceToast: true });
-
this.args.enabledForChanged?.(this.args.change.setting, newValue);
} catch (error) {
this.bufferedEnabledFor = oldValue;
diff --git a/frontend/discourse/tests/integration/components/admin-config-areas/upcoming-change-item-test.gjs b/frontend/discourse/tests/integration/components/admin-config-areas/upcoming-change-item-test.gjs
index 3015034062c..efeb71bc7aa 100644
--- a/frontend/discourse/tests/integration/components/admin-config-areas/upcoming-change-item-test.gjs
+++ b/frontend/discourse/tests/integration/components/admin-config-areas/upcoming-change-item-test.gjs
@@ -1,7 +1,8 @@
-import { render } from "@ember/test-helpers";
+import { fillIn, render } from "@ember/test-helpers";
import { module, test } from "qunit";
import UpcomingChangeItem from "discourse/admin/components/admin-config-areas/upcoming-change-item";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+import pretender, { response } from "discourse/tests/helpers/create-pretender";
import { i18n } from "discourse-i18n";
function buildChange(overrides = {}) {
@@ -249,4 +250,97 @@ module("Integration | Component | UpcomingChangeItem", function (hooks) {
);
});
});
+
+ test("selecting staff on a change that excludes 'everyone' saves the staff group before enabling", async function (assert) {
+ const requests = [];
+ let groupSaved = false;
+
+ pretender.put("/admin/config/upcoming-changes/groups", () => {
+ requests.push("groups");
+ groupSaved = true;
+ return response({ success: "OK" });
+ });
+ pretender.put("/admin/config/upcoming-changes/toggle", () => {
+ requests.push("toggle");
+ if (!groupSaved) {
+ return response(422, { errors: ["everyone is not an allowed target"] });
+ }
+ return response({ success: "OK" });
+ });
+
+ const change = buildChange({
+ setting: "reporting_improvements",
+ value: false,
+ upcoming_change: {
+ status: "beta",
+ impact: "feature,staff",
+ impact_type: "feature",
+ impact_role: "staff",
+ enabled_for: "no_one",
+ allow_enabled_for: ["staff", "specific_groups"],
+ },
+ });
+
+ await render(
+ <template>
+ <table>
+ <tbody><UpcomingChangeItem @change={{change}} /></tbody>
+ </table>
+ </template>
+ );
+
+ await fillIn(".upcoming-change__enabled-for", "staff");
+
+ assert.deepEqual(
+ requests,
+ ["groups", "toggle"],
+ "persists the staff group first, so the toggle passes instead of 422ing"
+ );
+ assert
+ .dom(".upcoming-change__enabled-for")
+ .hasValue("staff", "keeps staff selected");
+ });
+
+ test("selecting everyone toggles the change then clears any groups", async function (assert) {
+ const requests = [];
+
+ pretender.put("/admin/config/upcoming-changes/toggle", () => {
+ requests.push("toggle");
+ return response({ success: "OK" });
+ });
+ pretender.put("/admin/config/upcoming-changes/groups", () => {
+ requests.push("groups");
+ return response({ success: "OK" });
+ });
+
+ const change = buildChange({
+ value: false,
+ upcoming_change: {
+ status: "beta",
+ impact: "feature,all_members",
+ impact_type: "feature",
+ impact_role: "all_members",
+ enabled_for: "no_one",
+ },
+ });
+
+ await render(
+ <template>
+ <table>
+ <tbody><UpcomingChangeItem @change={{change}} /></tbody>
+ </table>
+ </template>
+ );
+
+ await fillIn(".upcoming-change__enabled-for", "everyone");
+
+ assert.deepEqual(
+ requests,
+ ["toggle", "groups"],
+ "enables first then clears groups when 'everyone' is allowed"
+ );
+ assert
+ .dom(".upcoming-change__enabled-for")
+ .hasValue("everyone", "keeps everyone selected");
+ });
});
diff --git a/spec/system/admin_upcoming_changes_spec.rb b/spec/system/admin_upcoming_changes_spec.rb
index 7164b26c0ea..4b96c6a2c71 100644
--- a/spec/system/admin_upcoming_changes_spec.rb
+++ b/spec/system/admin_upcoming_changes_spec.rb
@@ -260,6 +260,26 @@ describe "Admin upcoming changes" do
item = upcoming_changes_page.change_item(:enable_upload_debug_mode)
expect(item.enabled_for).to eq("staff")
end
+
+ it "enables the change for staff when everyone is excluded" do
+ mock_with_allow(%i[staff specific_groups])
+ SiteSetting.enable_upload_debug_mode = false
+
+ upcoming_changes_page.visit
+ item = upcoming_changes_page.change_item(:enable_upload_debug_mode)
+ item.select_enabled_for("staff")
+
+ expect(upcoming_changes_page).to have_enabled_for_success_toast(
+ "staff",
+ translation_args: {
+ staffGroupName: I18n.t("groups.default_names.staff").titleize,
+ },
+ )
+ expect(item).to be_enabled
+ expect(SiteSettingGroup.find_by(name: "enable_upload_debug_mode").group_ids).to include(
+ Group::AUTO_GROUPS[:staff].to_s,
+ )
+ end
end
it "can filter by name, description, plugin, status, impact type, or enabled/disabled" do