Add a bunch of reload-friendly class variables accessors plugin APIs
This commit is contained in:
parent
75e4f7f896
commit
51ef36abb4
|
@ -91,7 +91,9 @@ class Plugin::Instance
|
|||
end
|
||||
|
||||
def whitelist_staff_user_custom_field(field)
|
||||
User.register_plugin_staff_custom_field(field, self)
|
||||
reloadable_patch do |plugin|
|
||||
User.register_plugin_staff_custom_field(field, plugin) if plugin.enabled?
|
||||
end
|
||||
end
|
||||
|
||||
# Extend a class but check that the plugin is enabled
|
||||
|
@ -140,6 +142,30 @@ class Plugin::Instance
|
|||
end
|
||||
end
|
||||
|
||||
def topic_view_post_custom_fields_whitelister(&block)
|
||||
reloadable_patch do |plugin|
|
||||
TopicView.add_post_custom_fields_whitelister(&block) if plugin.enabled?
|
||||
end
|
||||
end
|
||||
|
||||
def add_preloaded_group_custom_field(field)
|
||||
reloadable_patch do |plugin|
|
||||
Group.preloaded_custom_field_names << field if plugin.enabled?
|
||||
end
|
||||
end
|
||||
|
||||
def add_preloaded_topic_list_custom_field(field)
|
||||
reloadable_patch do |plugin|
|
||||
TopicList.preloaded_custom_fields << field if plugin.enabled?
|
||||
end
|
||||
end
|
||||
|
||||
def add_permitted_post_create_param(name)
|
||||
reloadable_patch do |plugin|
|
||||
Post.permitted_create_params << name if plugin.enabled?
|
||||
end
|
||||
end
|
||||
|
||||
# Add validation method but check that the plugin is enabled
|
||||
def validate(klass, name, &block)
|
||||
klass = klass.to_s.classify.constantize
|
||||
|
@ -205,20 +231,41 @@ class Plugin::Instance
|
|||
|
||||
def notify_after_initialize
|
||||
color_schemes.each do |c|
|
||||
ColorScheme.create_from_base(name: c[:name], colors: c[:colors]) unless ColorScheme.where(name: c[:name]).exists?
|
||||
unless ColorScheme.where(name: c[:name]).exists?
|
||||
ColorScheme.create_from_base(name: c[:name], colors: c[:colors])
|
||||
end
|
||||
end
|
||||
|
||||
initializers.each do |callback|
|
||||
begin
|
||||
callback.call(self)
|
||||
rescue ActiveRecord::StatementInvalid => e
|
||||
# When running db:migrate for the first time on a new database, plugin initializers might
|
||||
# try to use models. Tolerate it.
|
||||
# When running `db:migrate` for the first time on a new database,
|
||||
# plugin initializers might try to use models.
|
||||
# Tolerate it.
|
||||
raise e unless e.message.try(:include?, "PG::UndefinedTable")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def register_topic_custom_field_type(name, type)
|
||||
reloadable_patch do |plugin|
|
||||
Topic.register_custom_field_type(name, type) if plugin.enabled?
|
||||
end
|
||||
end
|
||||
|
||||
def register_post_custom_field_type(name, type)
|
||||
reloadable_patch do |plugin|
|
||||
Post.register_custom_field_type(name, type) if plugin.enabled?
|
||||
end
|
||||
end
|
||||
|
||||
def register_group_custom_field_type(name, type)
|
||||
reloadable_patch do |plugin|
|
||||
Group.register_custom_field_type(name, type) if plugin.enabled?
|
||||
end
|
||||
end
|
||||
|
||||
def register_seedfu_fixtures(paths)
|
||||
paths = [paths] if !paths.kind_of?(Array)
|
||||
SeedFu.fixture_paths.concat(paths)
|
||||
|
|
Loading…
Reference in New Issue