FIX: Incompatibility between default_composer_category and default_subcategory_on_read_only_category (#22165)

This commit is contained in:
Juan David Martínez Cubillos 2023-06-16 15:56:25 -05:00 committed by GitHub
parent e061166a05
commit 93e5272223
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 26 deletions

View File

@ -7,11 +7,11 @@ export default Mixin.create({
openComposer(controller) { openComposer(controller) {
let categoryId = controller.get("category.id"); let categoryId = controller.get("category.id");
if (this.siteSettings.default_subcategory_on_read_only_category) { if (
if ( this.siteSettings.default_subcategory_on_read_only_category &&
!controller.canCreateTopicOnCategory && !controller.canCreateTopicOnCategory
controller.canCreateTopicOnSubCategory ) {
) { if (controller.canCreateTopicOnSubCategory) {
categoryId = controller.get("defaultSubcategory.id"); categoryId = controller.get("defaultSubcategory.id");
} else { } else {
categoryId = this.siteSettings.default_composer_category; categoryId = this.siteSettings.default_composer_category;
@ -20,6 +20,7 @@ export default Mixin.create({
if ( if (
categoryId && categoryId &&
!this.siteSettings.default_subcategory_on_read_only_category &&
controller.category.isUncategorizedCategory && controller.category.isUncategorizedCategory &&
!this.siteSettings.allow_uncategorized_topics !this.siteSettings.allow_uncategorized_topics
) { ) {

View File

@ -4,7 +4,7 @@ describe "Default to Subcategory when parent Category doesn't allow posting", ty
fab!(:user) { Fabricate(:user) } fab!(:user) { Fabricate(:user) }
fab!(:group) { Fabricate(:group) } fab!(:group) { Fabricate(:group) }
fab!(:group_user) { Fabricate(:group_user, user: user, group: group) } fab!(:group_user) { Fabricate(:group_user, user: user, group: group) }
fab!(:default_latest_category) { Fabricate(:category) } fab!(:default_latest_category) { Fabricate(:category, name: "General") }
fab!(:category) { Fabricate(:private_category, group: group, permission_type: 3) } fab!(:category) { Fabricate(:private_category, group: group, permission_type: 3) }
fab!(:subcategory) do fab!(:subcategory) do
Fabricate(:private_category, parent_category_id: category.id, group: group, permission_type: 1) Fabricate(:private_category, parent_category_id: category.id, group: group, permission_type: 1)
@ -25,28 +25,71 @@ describe "Default to Subcategory when parent Category doesn't allow posting", ty
describe "logged in user" do describe "logged in user" do
before { sign_in(user) } before { sign_in(user) }
describe "default_subcategory_on_read_only_category setting enabled and can't post on parent category" do describe "default_subcategory_on_read_only_category setting enabled and can't post on parent category" do
before do before { SiteSetting.default_subcategory_on_read_only_category = true }
SiteSetting.default_subcategory_on_read_only_category = true
SiteSetting.default_composer_category = default_latest_category.id describe "default_composer_category set" do
end before { SiteSetting.default_composer_category = default_latest_category.id }
describe "Category has subcategory" do describe "Can't post on parent category" do
it "should have 'New Topic' button enabled and default Subcategory set in the composer" do describe "Category has subcategory" do
category_page.visit(category) it "should have 'New Topic' button enabled and default Subcategory set in the composer" do
expect(category_page).to have_button("New Topic", disabled: false) category_page.visit(category)
category_page.new_topic_button.click expect(category_page).to have_button("New Topic", disabled: false)
select_kit = category_page.new_topic_button.click
PageObjects::Components::SelectKit.new("#reply-control.open .category-chooser") select_kit =
expect(select_kit).to have_selected_value(subcategory.id) PageObjects::Components::SelectKit.new("#reply-control.open .category-chooser")
expect(select_kit).to have_selected_value(subcategory.id)
end
end
describe "Category does not have subcategory" do
it "should have the 'New Topic' button enabled and default Subcategory set to latest default subcategory" do
category_page.visit(category_with_no_subcategory)
expect(category_page).to have_button("New Topic", disabled: false)
category_page.new_topic_button.click
select_kit =
PageObjects::Components::SelectKit.new("#reply-control.open .category-chooser")
expect(select_kit).to have_selected_value(default_latest_category.id)
end
end
end
describe "Can post on home page" do
it "should have the default category set in the composer" do
page.visit("latest")
expect(page).to have_button("New Topic", disabled: false)
page.find("#create-topic").click
select_kit =
PageObjects::Components::SelectKit.new("#reply-control.open .category-chooser")
expect(select_kit).to have_selected_value(default_latest_category.id)
end
end end
end end
describe "Category does not have subcategory" do
it "should have the 'New Topic' button enabled and default Subcategory set to latest default subcategory" do describe "default_composer_category not set" do
category_page.visit(category_with_no_subcategory) before do
expect(category_page).to have_button("New Topic", disabled: false) SiteSetting.default_composer_category = ""
category_page.new_topic_button.click SiteSetting.allow_uncategorized_topics = false
select_kit = end
PageObjects::Components::SelectKit.new("#reply-control.open .category-chooser") describe "Can't post on parent category" do
expect(select_kit).to have_selected_value(default_latest_category.id) describe "Category does not have subcategory" do
it "should have the 'New Topic' button enabled and default Subcategory not set" do
category_page.visit(category_with_no_subcategory)
expect(category_page).to have_button("New Topic", disabled: false)
category_page.new_topic_button.click
select_kit =
PageObjects::Components::SelectKit.new("#reply-control.open .category-chooser")
expect(select_kit).to have_selected_name("category…")
end
end
end
describe "Can post on home page" do
it "composer should open" do
page.visit("latest")
expect(page).to have_button("New Topic", disabled: false)
page.find("#create-topic").click
select_kit =
PageObjects::Components::SelectKit.new("#reply-control.open .category-chooser")
expect(select_kit).to have_selected_name("category…")
end
end end
end end
end end