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({
|
export default Mixin.create({
|
||||||
openComposer(controller) {
|
openComposer(controller) {
|
||||||
let categoryId = controller.get("category.id");
|
let categoryId = controller.get("category.id");
|
||||||
|
|
||||||
|
if (
|
||||||
|
!controller.canCreateTopicOnCategory &&
|
||||||
|
this.siteSettings.default_subcategory_on_read_only_category
|
||||||
|
) {
|
||||||
|
categoryId = controller.get("defaultSubcategory.id");
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
categoryId &&
|
categoryId &&
|
||||||
controller.category.isUncategorizedCategory &&
|
controller.category.isUncategorizedCategory &&
|
||||||
|
|
|
@ -153,14 +153,33 @@ export default (filterArg, params) => {
|
||||||
setupController(controller, model) {
|
setupController(controller, model) {
|
||||||
const topics = this.topics,
|
const topics = this.topics,
|
||||||
category = model.category,
|
category = model.category,
|
||||||
canCreateTopic = topics.get("can_create_topic"),
|
canCreateTopic = topics.get("can_create_topic");
|
||||||
canCreateTopicOnCategory =
|
|
||||||
|
let canCreateTopicOnCategory =
|
||||||
canCreateTopic && category.get("permission") === PermissionType.FULL;
|
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({
|
this.controllerFor("navigation/category").setProperties({
|
||||||
canCreateTopicOnCategory,
|
canCreateTopicOnCategory,
|
||||||
cannotCreateTopicOnCategory: !canCreateTopicOnCategory,
|
cannotCreateTopicOnCategory: !(
|
||||||
|
canCreateTopicOnCategory || canCreateTopicOnSubCategory
|
||||||
|
),
|
||||||
canCreateTopic,
|
canCreateTopic,
|
||||||
|
canCreateTopicOnSubCategory,
|
||||||
|
defaultSubcategory,
|
||||||
});
|
});
|
||||||
|
|
||||||
let topicOpts = {
|
let topicOpts = {
|
||||||
|
@ -174,6 +193,8 @@ export default (filterArg, params) => {
|
||||||
expandAllPinned: true,
|
expandAllPinned: true,
|
||||||
canCreateTopic,
|
canCreateTopic,
|
||||||
canCreateTopicOnCategory,
|
canCreateTopicOnCategory,
|
||||||
|
canCreateTopicOnSubCategory,
|
||||||
|
defaultSubcategory,
|
||||||
};
|
};
|
||||||
|
|
||||||
const p = category.get("params");
|
const p = category.get("params");
|
||||||
|
|
|
@ -1554,6 +1554,7 @@ en:
|
||||||
|
|
||||||
post_excerpt_maxlength: "Maximum length of a post excerpt / summary."
|
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."
|
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_mobile: "Show excerpt on pinned topics in mobile view."
|
||||||
show_pinned_excerpt_desktop: "Show excerpt on pinned topics in desktop 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."
|
post_onebox_maxlength: "Maximum length of a oneboxed Discourse post in characters."
|
||||||
|
|
|
@ -958,6 +958,9 @@ posting:
|
||||||
ja: 120
|
ja: 120
|
||||||
zh_CN: 120
|
zh_CN: 120
|
||||||
zh_TW: 120
|
zh_TW: 120
|
||||||
|
default_subcategory_on_read_only_category:
|
||||||
|
client: true
|
||||||
|
default: false
|
||||||
show_pinned_excerpt_mobile:
|
show_pinned_excerpt_mobile:
|
||||||
client: true
|
client: true
|
||||||
default: 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
|
find(".select-category-template").click
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def new_topic_button
|
||||||
|
find("#create-topic")
|
||||||
|
end
|
||||||
|
|
||||||
CATEGORY_NAVIGATION_NEW_NAV_ITEM_SELECTOR = ".category-navigation .nav-item_new"
|
CATEGORY_NAVIGATION_NEW_NAV_ITEM_SELECTOR = ".category-navigation .nav-item_new"
|
||||||
|
|
||||||
def has_no_new_topics?
|
def has_no_new_topics?
|
||||||
|
|
Loading…
Reference in New Issue