FEATURE: Make General the default category (#18383)
* FEATURE: Make General the default category * Set general as the default category in the composer model instead * use semicolon * Enable allow_uncategorized_topics in create_post spec helper for now * Check if general_category_id is set * Enable allow_uncategorized_topics for test env * Provide an option to the create_post helper to not set allow_uncategorized_topics * Add tests to check that category… is not present and that General is selected automatically
This commit is contained in:
parent
c1a7fa6b5d
commit
3b86974367
|
@ -143,7 +143,9 @@ const Composer = RestModel.extend({
|
|||
const oldCategoryId = this._categoryId;
|
||||
|
||||
if (isEmpty(categoryId)) {
|
||||
categoryId = null;
|
||||
// Set General as the default category
|
||||
const generalCategoryId = this.siteSettings.general_category_id;
|
||||
categoryId = generalCategoryId ? generalCategoryId : null;
|
||||
}
|
||||
this._categoryId = categoryId;
|
||||
|
||||
|
|
|
@ -39,8 +39,27 @@ acceptance("Composer", function (needs) {
|
|||
});
|
||||
needs.settings({
|
||||
enable_whispers: true,
|
||||
general_category_id: 1,
|
||||
});
|
||||
needs.site({
|
||||
can_tag_topics: true,
|
||||
categories: [
|
||||
{
|
||||
id: 1,
|
||||
name: "General",
|
||||
slug: "general",
|
||||
permission: 1,
|
||||
topic_template: null,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "test too",
|
||||
slug: "test-too",
|
||||
permission: 1,
|
||||
topic_template: "",
|
||||
},
|
||||
],
|
||||
});
|
||||
needs.site({ can_tag_topics: true });
|
||||
needs.pretender((server, helper) => {
|
||||
server.post("/uploads/lookup-urls", () => {
|
||||
return helper.response([]);
|
||||
|
@ -69,6 +88,8 @@ acceptance("Composer", function (needs) {
|
|||
test("Composer is opened", async function (assert) {
|
||||
await visit("/");
|
||||
await click("#create-topic");
|
||||
// Check that General category is selected
|
||||
assert.strictEqual(selectKit(".category-chooser").header().value(), "1");
|
||||
|
||||
assert.strictEqual(
|
||||
document.documentElement.style.getPropertyValue("--composer-height"),
|
||||
|
|
|
@ -126,6 +126,23 @@ module(
|
|||
assert.strictEqual(this.subject.header().label(), "category…");
|
||||
});
|
||||
|
||||
test("with allowUncategorized=null and generalCategoryId present", async function (assert) {
|
||||
this.siteSettings.allow_uncategorized_topics = false;
|
||||
this.siteSettings.general_category_id = 4;
|
||||
|
||||
await render(hbs`
|
||||
<CategoryChooser
|
||||
@value={{this.value}}
|
||||
@options={{hash
|
||||
allowUncategorized=null
|
||||
}}
|
||||
/>
|
||||
`);
|
||||
|
||||
assert.strictEqual(this.subject.header().value(), null);
|
||||
assert.strictEqual(this.subject.header().label(), "");
|
||||
});
|
||||
|
||||
test("with allowUncategorized=null none=true", async function (assert) {
|
||||
this.siteSettings.allow_uncategorized_topics = false;
|
||||
|
||||
|
|
|
@ -44,7 +44,10 @@ export default ComboBoxComponent.extend({
|
|||
) {
|
||||
return Category.findUncategorized();
|
||||
} else {
|
||||
return this.defaultItem(null, htmlSafe(I18n.t("category.choose")));
|
||||
const generalCategoryId = this.siteSettings.general_category_id;
|
||||
if (!generalCategoryId) {
|
||||
return this.defaultItem(null, htmlSafe(I18n.t("category.choose")));
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -68,6 +68,11 @@ Discourse::Application.configure do
|
|||
s.set_regardless_of_locale(:download_remote_images_to_local, false)
|
||||
s.set_regardless_of_locale(:unique_posts_mins, 0)
|
||||
s.set_regardless_of_locale(:max_consecutive_replies, 0)
|
||||
|
||||
# Most existing tests were written assuming allow_uncategorized_topics
|
||||
# was enabled, so we should set it to true.
|
||||
s.set_regardless_of_locale(:allow_uncategorized_topics, true)
|
||||
|
||||
# disable plugins
|
||||
if ENV['LOAD_PLUGINS'] == '1'
|
||||
s.set_regardless_of_locale(:discourse_narrative_bot_enabled, false)
|
||||
|
|
|
@ -806,7 +806,7 @@ posting:
|
|||
max_emojis_in_title: 1
|
||||
allow_uncategorized_topics:
|
||||
client: true
|
||||
default: true
|
||||
default: false
|
||||
refresh: true
|
||||
allow_duplicate_topic_titles: false
|
||||
allow_duplicate_topic_titles_category: false
|
||||
|
@ -2304,6 +2304,7 @@ uncategorized:
|
|||
general_category_id:
|
||||
default: -1
|
||||
hidden: true
|
||||
client: true
|
||||
meta_category_id:
|
||||
default: -1
|
||||
hidden: true
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DisableAllowUncategorizedNewSites < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
result = execute <<~SQL
|
||||
SELECT created_at
|
||||
FROM schema_migration_details
|
||||
ORDER BY created_at
|
||||
LIMIT 1
|
||||
SQL
|
||||
|
||||
# keep allow uncategorized for existing sites
|
||||
if result.first['created_at'].to_datetime < 1.hour.ago
|
||||
execute <<~SQL
|
||||
INSERT INTO site_settings(name, data_type, value, created_at, updated_at)
|
||||
VALUES('allow_uncategorized_topics', 5, 't', NOW(), NOW())
|
||||
ON CONFLICT (name) DO NOTHING
|
||||
SQL
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
|
@ -6,7 +6,7 @@ RSpec.describe TopicConverter do
|
|||
fab!(:author) { Fabricate(:user) }
|
||||
fab!(:category) { Fabricate(:category, topic_count: 1) }
|
||||
fab!(:private_message) { Fabricate(:private_message_topic, user: author) } # creates a topic without a first post
|
||||
let(:first_post) { create_post(user: author, topic: private_message) }
|
||||
let(:first_post) { create_post(user: author, topic: private_message, allow_uncategorized_topics: false) }
|
||||
let(:other_user) { private_message.topic_allowed_users.find { |u| u.user != author }.user }
|
||||
|
||||
let(:uncategorized_category) do
|
||||
|
|
|
@ -45,6 +45,12 @@ module Helpers
|
|||
end
|
||||
|
||||
def create_post(args = {})
|
||||
# Pretty much all the tests with `create_post` will fail without this
|
||||
# since allow_uncategorized_topics is now false by default
|
||||
unless args[:allow_uncategorized_topics] == false
|
||||
SiteSetting.allow_uncategorized_topics = true
|
||||
end
|
||||
|
||||
args[:title] ||= "This is my title #{Helpers.next_seq}"
|
||||
args[:raw] ||= "This is the raw body of my post, it is cool #{Helpers.next_seq}"
|
||||
args[:topic_id] = args[:topic].id if args[:topic]
|
||||
|
|
Loading…
Reference in New Issue