FIX: Fix for Default to subcategory when parent category does not allow posting (#21537)
* FIX: Fix for Default to subcategory when parent category does not allow posting * added tests for edge case scenario * implemented correct behaviour when parent category doesn't have subcategories * implemented new fabricator for categories and suggested changes
This commit is contained in:
parent
0ffe463d79
commit
774313ef0f
|
@ -7,11 +7,15 @@ export default Mixin.create({
|
|||
openComposer(controller) {
|
||||
let categoryId = controller.get("category.id");
|
||||
|
||||
if (this.siteSettings.default_subcategory_on_read_only_category) {
|
||||
if (
|
||||
!controller.canCreateTopicOnCategory &&
|
||||
this.siteSettings.default_subcategory_on_read_only_category
|
||||
controller.canCreateTopicOnSubCategory
|
||||
) {
|
||||
categoryId = controller.get("defaultSubcategory.id");
|
||||
} else {
|
||||
categoryId = this.siteSettings.default_composer_category;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
|
|
|
@ -157,26 +157,24 @@ export default (filterArg, params) => {
|
|||
|
||||
let canCreateTopicOnCategory =
|
||||
canCreateTopic && category.get("permission") === PermissionType.FULL;
|
||||
|
||||
let cannotCreateTopicOnCategory = !canCreateTopicOnCategory;
|
||||
let defaultSubcategory;
|
||||
let canCreateTopicOnSubCategory;
|
||||
|
||||
if (
|
||||
!canCreateTopicOnCategory &&
|
||||
this.siteSettings.default_subcategory_on_read_only_category
|
||||
) {
|
||||
if (this.siteSettings.default_subcategory_on_read_only_category) {
|
||||
cannotCreateTopicOnCategory = false;
|
||||
|
||||
if (!canCreateTopicOnCategory && category.subcategories) {
|
||||
defaultSubcategory = category.subcategories.find((subcategory) => {
|
||||
return subcategory.get("permission") === PermissionType.FULL;
|
||||
});
|
||||
|
||||
canCreateTopicOnSubCategory = !!defaultSubcategory;
|
||||
}
|
||||
}
|
||||
|
||||
this.controllerFor("navigation/category").setProperties({
|
||||
canCreateTopicOnCategory,
|
||||
cannotCreateTopicOnCategory: !(
|
||||
canCreateTopicOnCategory || canCreateTopicOnSubCategory
|
||||
),
|
||||
cannotCreateTopicOnCategory,
|
||||
canCreateTopic,
|
||||
canCreateTopicOnSubCategory,
|
||||
defaultSubcategory,
|
||||
|
|
|
@ -8,7 +8,7 @@ end
|
|||
|
||||
Fabricator(:category_with_definition, from: :category) { skip_category_definition false }
|
||||
|
||||
Fabricator(:private_category, from: :category) do
|
||||
Fabricator(:category_with_group_and_permission, from: :category) do
|
||||
transient :group
|
||||
transient :permission_type
|
||||
|
||||
|
@ -17,7 +17,6 @@ Fabricator(:private_category, from: :category) do
|
|||
user
|
||||
|
||||
after_build do |cat, transients|
|
||||
cat.update!(read_restricted: true)
|
||||
cat.category_groups.build(
|
||||
group_id: transients[:group].id,
|
||||
permission_type: transients[:permission_type] || CategoryGroup.permission_types[:full],
|
||||
|
@ -25,6 +24,10 @@ Fabricator(:private_category, from: :category) do
|
|||
end
|
||||
end
|
||||
|
||||
Fabricator(:private_category, from: :category_with_group_and_permission) do
|
||||
after_build { |cat, transients| cat.update!(read_restricted: true) }
|
||||
end
|
||||
|
||||
Fabricator(:private_category_with_definition, from: :private_category) do
|
||||
skip_category_definition false
|
||||
end
|
||||
|
|
|
@ -6,32 +6,63 @@ describe "Default to Subcategory when parent Category doesn't allow posting",
|
|||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:group) { Fabricate(:group) }
|
||||
fab!(:group_user) { Fabricate(:group_user, user: user, group: group) }
|
||||
fab!(:default_latest_category) { Fabricate(:category) }
|
||||
fab!(:category) { Fabricate(:private_category, group: group, permission_type: 3) }
|
||||
fab!(:subcategory) do
|
||||
Fabricate(:private_category, parent_category_id: category.id, group: group, permission_type: 1)
|
||||
end
|
||||
fab!(:category_with_no_subcategory) do
|
||||
Fabricate(:category_with_group_and_permission, group: group, permission_type: 3)
|
||||
end
|
||||
let(:category_page) { PageObjects::Pages::Category.new }
|
||||
|
||||
describe "anon user" do
|
||||
it "can visit the category" do
|
||||
category_page.visit(category_with_no_subcategory)
|
||||
select_kit = PageObjects::Components::SelectKit.new(page.find(".navigation-container"))
|
||||
expect(select_kit).to have_selected_value(category_with_no_subcategory.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe "logged in user" do
|
||||
before { sign_in(user) }
|
||||
|
||||
describe "Setting enabled and can't post on parent category" do
|
||||
before { SiteSetting.default_subcategory_on_read_only_category = true }
|
||||
|
||||
describe "default_subcategory_on_read_only_category setting enabled and can't post on parent category" do
|
||||
before do
|
||||
SiteSetting.default_subcategory_on_read_only_category = true
|
||||
SiteSetting.default_composer_category = default_latest_category.id
|
||||
end
|
||||
describe "Category has subcategory" do
|
||||
it "should have 'New Topic' button enabled and default Subcategory set in the composer" do
|
||||
category_page.visit(category)
|
||||
expect(category_page).to have_button("New Topic", disabled: false)
|
||||
category_page.new_topic_button.click
|
||||
select_kit =
|
||||
PageObjects::Components::SelectKit.new(page.find("#reply-control.open .category-chooser"))
|
||||
PageObjects::Components::SelectKit.new(
|
||||
page.find("#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(
|
||||
page.find("#reply-control.open .category-chooser"),
|
||||
)
|
||||
expect(select_kit).to have_selected_value(default_latest_category.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "Setting disabled and can't post on parent category" do
|
||||
before { SiteSetting.default_subcategory_on_read_only_category = false }
|
||||
|
||||
it "should have 'New Topic' button disabled" do
|
||||
category_page.visit(category)
|
||||
expect(category_page).to have_button("New Topic", disabled: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue