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) {
|
openComposer(controller) {
|
||||||
let categoryId = controller.get("category.id");
|
let categoryId = controller.get("category.id");
|
||||||
|
|
||||||
if (
|
if (this.siteSettings.default_subcategory_on_read_only_category) {
|
||||||
!controller.canCreateTopicOnCategory &&
|
if (
|
||||||
this.siteSettings.default_subcategory_on_read_only_category
|
!controller.canCreateTopicOnCategory &&
|
||||||
) {
|
controller.canCreateTopicOnSubCategory
|
||||||
categoryId = controller.get("defaultSubcategory.id");
|
) {
|
||||||
|
categoryId = controller.get("defaultSubcategory.id");
|
||||||
|
} else {
|
||||||
|
categoryId = this.siteSettings.default_composer_category;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -157,26 +157,24 @@ export default (filterArg, params) => {
|
||||||
|
|
||||||
let canCreateTopicOnCategory =
|
let canCreateTopicOnCategory =
|
||||||
canCreateTopic && category.get("permission") === PermissionType.FULL;
|
canCreateTopic && category.get("permission") === PermissionType.FULL;
|
||||||
|
let cannotCreateTopicOnCategory = !canCreateTopicOnCategory;
|
||||||
let defaultSubcategory;
|
let defaultSubcategory;
|
||||||
let canCreateTopicOnSubCategory;
|
let canCreateTopicOnSubCategory;
|
||||||
|
|
||||||
if (
|
if (this.siteSettings.default_subcategory_on_read_only_category) {
|
||||||
!canCreateTopicOnCategory &&
|
cannotCreateTopicOnCategory = false;
|
||||||
this.siteSettings.default_subcategory_on_read_only_category
|
|
||||||
) {
|
|
||||||
defaultSubcategory = category.subcategories.find((subcategory) => {
|
|
||||||
return subcategory.get("permission") === PermissionType.FULL;
|
|
||||||
});
|
|
||||||
|
|
||||||
canCreateTopicOnSubCategory = !!defaultSubcategory;
|
if (!canCreateTopicOnCategory && category.subcategories) {
|
||||||
|
defaultSubcategory = category.subcategories.find((subcategory) => {
|
||||||
|
return subcategory.get("permission") === PermissionType.FULL;
|
||||||
|
});
|
||||||
|
canCreateTopicOnSubCategory = !!defaultSubcategory;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.controllerFor("navigation/category").setProperties({
|
this.controllerFor("navigation/category").setProperties({
|
||||||
canCreateTopicOnCategory,
|
canCreateTopicOnCategory,
|
||||||
cannotCreateTopicOnCategory: !(
|
cannotCreateTopicOnCategory,
|
||||||
canCreateTopicOnCategory || canCreateTopicOnSubCategory
|
|
||||||
),
|
|
||||||
canCreateTopic,
|
canCreateTopic,
|
||||||
canCreateTopicOnSubCategory,
|
canCreateTopicOnSubCategory,
|
||||||
defaultSubcategory,
|
defaultSubcategory,
|
||||||
|
|
|
@ -8,7 +8,7 @@ end
|
||||||
|
|
||||||
Fabricator(:category_with_definition, from: :category) { skip_category_definition false }
|
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 :group
|
||||||
transient :permission_type
|
transient :permission_type
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ Fabricator(:private_category, from: :category) do
|
||||||
user
|
user
|
||||||
|
|
||||||
after_build do |cat, transients|
|
after_build do |cat, transients|
|
||||||
cat.update!(read_restricted: true)
|
|
||||||
cat.category_groups.build(
|
cat.category_groups.build(
|
||||||
group_id: transients[:group].id,
|
group_id: transients[:group].id,
|
||||||
permission_type: transients[:permission_type] || CategoryGroup.permission_types[:full],
|
permission_type: transients[:permission_type] || CategoryGroup.permission_types[:full],
|
||||||
|
@ -25,6 +24,10 @@ Fabricator(:private_category, from: :category) do
|
||||||
end
|
end
|
||||||
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
|
Fabricator(:private_category_with_definition, from: :private_category) do
|
||||||
skip_category_definition false
|
skip_category_definition false
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,32 +6,63 @@ describe "Default to Subcategory when parent Category doesn't allow posting",
|
||||||
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!(: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)
|
||||||
end
|
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 }
|
let(:category_page) { PageObjects::Pages::Category.new }
|
||||||
before { sign_in(user) }
|
|
||||||
|
|
||||||
describe "Setting enabled and can't post on parent category" do
|
describe "anon user" do
|
||||||
before { SiteSetting.default_subcategory_on_read_only_category = true }
|
it "can visit the category" do
|
||||||
|
category_page.visit(category_with_no_subcategory)
|
||||||
it "should have 'New Topic' button enabled and default Subcategory set in the composer" do
|
select_kit = PageObjects::Components::SelectKit.new(page.find(".navigation-container"))
|
||||||
category_page.visit(category)
|
expect(select_kit).to have_selected_value(category_with_no_subcategory.id)
|
||||||
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(subcategory.id)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "Setting disabled and can't post on parent category" do
|
describe "logged in user" do
|
||||||
before { SiteSetting.default_subcategory_on_read_only_category = false }
|
before { sign_in(user) }
|
||||||
|
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"),
|
||||||
|
)
|
||||||
|
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
|
||||||
|
|
||||||
it "should have 'New Topic' button disabled" do
|
describe "Setting disabled and can't post on parent category" do
|
||||||
category_page.visit(category)
|
before { SiteSetting.default_subcategory_on_read_only_category = false }
|
||||||
expect(category_page).to have_button("New Topic", disabled: true)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue