FEATURE: Default Composer Category Site Setting (#18967)

* FEATURE: Default Composer Category Site Setting

- Create the default_composer_category site setting
- Replace general_category_id logic for auto selecting the composer
  category
- Prevent Uncategorized from being selected if not allowed
- Add default_composer_category option to seeded categories
- Create a migration to populate the default_composer_category site
  setting if there is a general_category_id populated
- Added some tests

* Add missing translation for the new site setting

* fix some js tests

* Just check that the header value is null
This commit is contained in:
Blake Erickson
2022-11-14 11:09:57 -07:00
committed by GitHub
parent 8c48285145
commit 7be53b1588
10 changed files with 181 additions and 12 deletions

View File

@ -0,0 +1,22 @@
# frozen_string_literal: true
## If the general_category_id has a value, set the *new*
# default_composer_category site setting to match
class PopulateDefaultComposerCategory < ActiveRecord::Migration[7.0]
def up
general_category_id = DB.query_single("SELECT value FROM site_settings WHERE name = 'general_category_id'")
return if general_category_id.blank? || general_category_id[0].to_i < 0
default_composer_category = DB.query_single("SELECT value FROM site_settings where name = 'default_composer_category'")
return if !default_composer_category.blank?
DB.exec(
"INSERT INTO site_settings(name, value, data_type, created_at, updated_at)
VALUES('default_composer_category', :setting, '16', NOW(), NOW())",
setting: general_category_id[0].to_i
)
end
def down
raise ActiveRecord::IrreversibleMigration
end
end