Skip to content

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

FIX: auto-switch to private when selecting restricted parent category (#37530)

Régis Hanol471b1a662cab
diff --git a/frontend/discourse/admin/components/upsert-category/general.gjs b/frontend/discourse/admin/components/upsert-category/general.gjs
index 72604b65720..82433238253 100644
--- a/frontend/discourse/admin/components/upsert-category/general.gjs
+++ b/frontend/discourse/admin/components/upsert-category/general.gjs
@@ -25,7 +25,6 @@ export default class UpsertCategoryGeneral extends Component {
@service siteSettings;
@tracked categoryVisibilityState = null;
- @tracked userModifiedPermissions = false;
uncategorizedSiteSettingLink = getURL(
"/admin/site_settings/category/all_results?filter=allow_uncategorized_topics"
);
@@ -107,7 +106,6 @@ export default class UpsertCategoryGeneral extends Component {
};
});
- this.userModifiedPermissions = true;
this.#setFormPermissions(newPermissions);
}
@@ -184,7 +182,6 @@ export default class UpsertCategoryGeneral extends Component {
}
this.categoryVisibilityState = value;
- this.userModifiedPermissions = true;
if (value === "public") {
this.#setFormPermissions([this.#createEveryoneFullPermission()]);
@@ -200,9 +197,8 @@ export default class UpsertCategoryGeneral extends Component {
@action
async onParentCategoryChange(parentCategoryId) {
if (!parentCategoryId) {
- if (!this.userModifiedPermissions) {
- this.#setFormPermissions([this.#createEveryoneFullPermission()]);
- }
+ this.categoryVisibilityState = null;
+ this.#setFormPermissions([this.#createEveryoneFullPermission()]);
return;
}
@@ -216,6 +212,8 @@ export default class UpsertCategoryGeneral extends Component {
);
if (!hasEveryone) {
+ this.categoryVisibilityState = null;
+
const newPermissions = parentCategory.permissions.map((p) => ({
group_name: p.group_name,
group_id: p.group_id,
diff --git a/frontend/discourse/app/form-kit/components/fk/control/conditional-content.gjs b/frontend/discourse/app/form-kit/components/fk/control/conditional-content.gjs
index 62e01674497..227864e9af0 100644
--- a/frontend/discourse/app/form-kit/components/fk/control/conditional-content.gjs
+++ b/frontend/discourse/app/form-kit/components/fk/control/conditional-content.gjs
@@ -27,6 +27,10 @@ export default class FKControlConditionalContent extends Component {
@tracked manuallySetName = null;
get activeName() {
+ // If onChange is provided, parent controls state - always use @activeName
+ if (this.args.onChange) {
+ return this.args.activeName;
+ }
return this.manuallySetName ?? this.args.activeName;
}
diff --git a/spec/system/page_objects/pages/category.rb b/spec/system/page_objects/pages/category.rb
index e3b89fab3f8..8aeac4137c9 100644
--- a/spec/system/page_objects/pages/category.rb
+++ b/spec/system/page_objects/pages/category.rb
@@ -99,7 +99,7 @@ module PageObjects
end
def toggle_advanced_settings
- find(".d-toggle-switch .d-toggle-switch__checkbox-slider").click
+ PageObjects::Components::DToggleSwitch.new(".d-toggle-switch__checkbox").toggle
self
end
diff --git a/spec/system/simplified_category_creation_spec.rb b/spec/system/simplified_category_creation_spec.rb
index e1d43a6dfcf..1a95d2012bd 100644
--- a/spec/system/simplified_category_creation_spec.rb
+++ b/spec/system/simplified_category_creation_spec.rb
@@ -88,6 +88,19 @@ describe "Simplified Category Creation" do
expect(page).to have_css(".edit-category-security")
expect(page).to have_css(".edit-category-settings")
end
+
+ it "automatically switches to private when selecting a restricted parent" do
+ restricted_parent =
+ Fabricate(:category, name: "Restricted Parent", permissions: { group.name => :full })
+
+ category_page.visit_new_category
+
+ parent_chooser = PageObjects::Components::SelectKit.new(".category-chooser")
+ parent_chooser.expand
+ parent_chooser.select_row_by_value(restricted_parent.id)
+
+ expect(page).to have_css(".group-chooser")
+ end
end
describe "Security Tab" do