FEATURE: Default to subcategory when parent category does not allow posting (#21228)
added site toggle functionality through site settings added tests to implemented feature Introduced suggested correction renamed find_new_topic method and deleted click_new_topic_button method
This commit is contained in:
parent
616885895a
commit
83d2f9ef78
|
@ -6,6 +6,14 @@ import { getOwner } from "discourse-common/lib/get-owner";
|
|||
export default Mixin.create({
|
||||
openComposer(controller) {
|
||||
let categoryId = controller.get("category.id");
|
||||
|
||||
if (
|
||||
!controller.canCreateTopicOnCategory &&
|
||||
this.siteSettings.default_subcategory_on_read_only_category
|
||||
) {
|
||||
categoryId = controller.get("defaultSubcategory.id");
|
||||
}
|
||||
|
||||
if (
|
||||
categoryId &&
|
||||
controller.category.isUncategorizedCategory &&
|
||||
|
|
|
@ -153,14 +153,33 @@ export default (filterArg, params) => {
|
|||
setupController(controller, model) {
|
||||
const topics = this.topics,
|
||||
category = model.category,
|
||||
canCreateTopic = topics.get("can_create_topic"),
|
||||
canCreateTopicOnCategory =
|
||||
canCreateTopic && category.get("permission") === PermissionType.FULL;
|
||||
canCreateTopic = topics.get("can_create_topic");
|
||||
|
||||
let canCreateTopicOnCategory =
|
||||
canCreateTopic && category.get("permission") === PermissionType.FULL;
|
||||
|
||||
let defaultSubcategory;
|
||||
let canCreateTopicOnSubCategory;
|
||||
|
||||
if (
|
||||
!canCreateTopicOnCategory &&
|
||||
this.siteSettings.default_subcategory_on_read_only_category
|
||||
) {
|
||||
defaultSubcategory = category.subcategories.find((subcategory) => {
|
||||
return subcategory.get("permission") === PermissionType.FULL;
|
||||
});
|
||||
|
||||
canCreateTopicOnSubCategory = !!defaultSubcategory;
|
||||
}
|
||||
|
||||
this.controllerFor("navigation/category").setProperties({
|
||||
canCreateTopicOnCategory,
|
||||
cannotCreateTopicOnCategory: !canCreateTopicOnCategory,
|
||||
cannotCreateTopicOnCategory: !(
|
||||
canCreateTopicOnCategory || canCreateTopicOnSubCategory
|
||||
),
|
||||
canCreateTopic,
|
||||
canCreateTopicOnSubCategory,
|
||||
defaultSubcategory,
|
||||
});
|
||||
|
||||
let topicOpts = {
|
||||
|
@ -174,6 +193,8 @@ export default (filterArg, params) => {
|
|||
expandAllPinned: true,
|
||||
canCreateTopic,
|
||||
canCreateTopicOnCategory,
|
||||
canCreateTopicOnSubCategory,
|
||||
defaultSubcategory,
|
||||
};
|
||||
|
||||
const p = category.get("params");
|
||||
|
|
|
@ -1554,6 +1554,7 @@ en:
|
|||
|
||||
post_excerpt_maxlength: "Maximum length of a post excerpt / summary."
|
||||
topic_excerpt_maxlength: "Maximum length of a topic excerpt / summary, generated from the first post in a topic."
|
||||
default_subcategory_on_read_only_category: "Enables 'New Topic' button and selects a default subcategory to post on categories where the user is not allowed to create a new topic."
|
||||
show_pinned_excerpt_mobile: "Show excerpt on pinned topics in mobile view."
|
||||
show_pinned_excerpt_desktop: "Show excerpt on pinned topics in desktop view."
|
||||
post_onebox_maxlength: "Maximum length of a oneboxed Discourse post in characters."
|
||||
|
|
|
@ -958,6 +958,9 @@ posting:
|
|||
ja: 120
|
||||
zh_CN: 120
|
||||
zh_TW: 120
|
||||
default_subcategory_on_read_only_category:
|
||||
client: true
|
||||
default: false
|
||||
show_pinned_excerpt_mobile:
|
||||
client: true
|
||||
default: true
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
describe "Default to Subcategory when parent Category doesn't allow posting",
|
||||
type: :system,
|
||||
js: true do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:group) { Fabricate(:group) }
|
||||
fab!(:group_user) { Fabricate(:group_user, user: user, group: group) }
|
||||
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
|
||||
let(:category_page) { PageObjects::Pages::Category.new }
|
||||
before { sign_in(user) }
|
||||
|
||||
describe "Setting enabled and can't post on parent category" do
|
||||
before { SiteSetting.default_subcategory_on_read_only_category = true }
|
||||
|
||||
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 "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
|
|
@ -65,6 +65,10 @@ module PageObjects
|
|||
find(".select-category-template").click
|
||||
end
|
||||
|
||||
def new_topic_button
|
||||
find("#create-topic")
|
||||
end
|
||||
|
||||
CATEGORY_NAVIGATION_NEW_NAV_ITEM_SELECTOR = ".category-navigation .nav-item_new"
|
||||
|
||||
def has_no_new_topics?
|
||||
|
|
Loading…
Reference in New Issue