mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 14:38:17 +08:00
DEV: allow the plugin to register valid site setting areas (#29432)
In this PR, we defined the ability to group site settings by area - https://github.com/discourse/discourse/pull/28570 Plugins should be able to register in their own areas.
This commit is contained in:
parent
4529b0614c
commit
0839bce7b6
|
@ -12,7 +12,7 @@ class Admin::Config::SiteSettingsController < Admin::AdminController
|
||||||
# UI itself uses the Admin::SiteSettingsController#index endpoint,
|
# UI itself uses the Admin::SiteSettingsController#index endpoint,
|
||||||
# which also supports a `category` and `plugin` filter.
|
# which also supports a `category` and `plugin` filter.
|
||||||
def index
|
def index
|
||||||
if params[:filter_names].blank? && SiteSetting::VALID_AREAS.exclude?(params[:filter_area])
|
if params[:filter_names].blank? && SiteSetting.valid_areas.exclude?(params[:filter_area])
|
||||||
raise Discourse::InvalidParameters
|
raise Discourse::InvalidParameters
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,7 @@ class DiscoursePluginRegistry
|
||||||
define_register :demon_processes, Set
|
define_register :demon_processes, Set
|
||||||
define_register :groups_callback_for_users_search_controller_action, Hash
|
define_register :groups_callback_for_users_search_controller_action, Hash
|
||||||
define_register :mail_pollers, Set
|
define_register :mail_pollers, Set
|
||||||
|
define_register :site_setting_areas, Set
|
||||||
|
|
||||||
define_filtered_register :staff_user_custom_fields
|
define_filtered_register :staff_user_custom_fields
|
||||||
define_filtered_register :public_user_custom_fields
|
define_filtered_register :public_user_custom_fields
|
||||||
|
|
|
@ -849,6 +849,14 @@ class Plugin::Instance
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Site setting areas are a way to group site settings below
|
||||||
|
# the setting category level. This is useful for creating focused
|
||||||
|
# config areas that update a small selection of settings, and otherwise
|
||||||
|
# grouping related settings in the UI.
|
||||||
|
def register_site_setting_area(area)
|
||||||
|
DiscoursePluginRegistry.site_setting_areas << area
|
||||||
|
end
|
||||||
|
|
||||||
def javascript_includes
|
def javascript_includes
|
||||||
assets
|
assets
|
||||||
.map do |asset, opts|
|
.map do |asset, opts|
|
||||||
|
|
|
@ -523,6 +523,10 @@ module SiteSettingExtension
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def valid_areas
|
||||||
|
Set.new(SiteSetting::VALID_AREAS | DiscoursePluginRegistry.site_setting_areas.to_a)
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def clear_cache!
|
def clear_cache!
|
||||||
|
@ -695,9 +699,9 @@ module SiteSettingExtension
|
||||||
|
|
||||||
if opts[:area]
|
if opts[:area]
|
||||||
split_areas = opts[:area].split("|")
|
split_areas = opts[:area].split("|")
|
||||||
if split_areas.any? { |area| !SiteSetting::VALID_AREAS.include?(area) }
|
if split_areas.any? { |area| !SiteSetting.valid_areas.include?(area) }
|
||||||
raise Discourse::InvalidParameters.new(
|
raise Discourse::InvalidParameters.new(
|
||||||
"Area is incorrect. Valid areas: #{SiteSetting::VALID_AREAS.join(", ")}",
|
"Area is invalid, valid areas are: #{SiteSetting.valid_areas.join(", ")}",
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
areas[name] = split_areas
|
areas[name] = split_areas
|
||||||
|
|
|
@ -510,6 +510,17 @@ RSpec.describe SiteSettingExtension do
|
||||||
settings.refresh!
|
settings.refresh!
|
||||||
}.to raise_error(Discourse::InvalidParameters)
|
}.to raise_error(Discourse::InvalidParameters)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "allows plugin to register valid areas" do
|
||||||
|
plugin = Plugin::Instance.new nil, "/tmp/test.rb"
|
||||||
|
plugin.register_site_setting_area("plugin_area")
|
||||||
|
settings.setting(:test_plugin_setting, 88, area: "plugin_area")
|
||||||
|
expect(
|
||||||
|
settings
|
||||||
|
.all_settings(filter_area: "plugin_area", include_locale_setting: false)
|
||||||
|
.map { |s| s[:setting].to_sym },
|
||||||
|
).to eq(%i[test_plugin_setting])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "setting with a validator" do
|
describe "setting with a validator" do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user