A platform for community discussion. Free, open, simple.
FIX: Remove `plugin.enabled?` checks at initialization time (#6166)
David Taylor0d0d78841b02
diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rbindex 2e92194cfe8..b4d1eec1f50 100644--- a/app/controllers/posts_controller.rb+++ b/app/controllers/posts_controller.rb@@ -615,8 +615,8 @@ class PostsController < ApplicationController:visible]- if Post.permitted_create_params.present?- permitted.concat(Post.permitted_create_params.to_a)+ Post.plugin_permitted_create_params.each do |key, plugin|+ permitted << key if plugin.enabled?end# param munging for WordPressdiff --git a/app/models/post.rb b/app/models/post.rbindex 30def11cf6b..a98cd178077 100644--- a/app/models/post.rb+++ b/app/models/post.rb@@ -19,8 +19,8 @@ class Post < ActiveRecord::Baseinclude HasCustomFieldsinclude LimitedEdit- cattr_accessor :permitted_create_params- self.permitted_create_params = Set.new+ cattr_accessor :plugin_permitted_create_params+ self.plugin_permitted_create_params = {}# increase this number to force a system wide post rebake# Version 1, was the initial versiondiff --git a/lib/plugin/instance.rb b/lib/plugin/instance.rbindex 8f47f1fdc43..770577eec16 100644--- a/lib/plugin/instance.rb+++ b/lib/plugin/instance.rb@@ -92,26 +92,26 @@ class Plugin::Instanceendend+ # Applies to all sites in a multisite environment. Ignores plugin.enabled?def add_report(name, &block)reloadable_patch do |plugin|- if plugin.enabled?- Report.add_report(name, &block)- end+ Report.add_report(name, &block)endend+ # Applies to all sites in a multisite environment. Ignores plugin.enabled?def replace_flagssettings = ::FlagSettings.newyield settingsreloadable_patch do |plugin|- ::PostActionType.replace_flag_settings(settings) if plugin.enabled?+ ::PostActionType.replace_flag_settings(settings)endenddef whitelist_staff_user_custom_field(field)reloadable_patch do |plugin|- ::User.register_plugin_staff_custom_field(field, plugin) if plugin.enabled?+ ::User.register_plugin_staff_custom_field(field, plugin) # plugin.enabled? is checked at runtimeendend@@ -122,9 +122,10 @@ class Plugin::Instanceendend+ # Applies to all sites in a multisite environment. Ignores plugin.enabled?def add_body_class(class_name)reloadable_patch do |plugin|- ::ApplicationHelper.extra_body_classes << class_name if plugin.enabled?+ ::ApplicationHelper.extra_body_classes << class_nameendend@@ -180,27 +181,34 @@ class Plugin::Instanceendend+ # Add a post_custom_fields_whitelister block to the TopicView, respecting if the plugin is enableddef topic_view_post_custom_fields_whitelister(&block)reloadable_patch do |plugin|- ::TopicView.add_post_custom_fields_whitelister(&block) if plugin.enabled?+ ::TopicView.add_post_custom_fields_whitelister do |user|+ return [] unless plugin.enabled?+ block.call(user)+ endendend+ # Applies to all sites in a multisite environment. Ignores plugin.enabled?def add_preloaded_group_custom_field(field)reloadable_patch do |plugin|- ::Group.preloaded_custom_field_names << field if plugin.enabled?+ ::Group.preloaded_custom_field_names << fieldendend+ # Applies to all sites in a multisite environment. Ignores plugin.enabled?def add_preloaded_topic_list_custom_field(field)reloadable_patch do |plugin|- ::TopicList.preloaded_custom_fields << field if plugin.enabled?+ ::TopicList.preloaded_custom_fields << fieldendend+ # Add a permitted_create_param to Post, respecting if the plugin is enableddef add_permitted_post_create_param(name)reloadable_patch do |plugin|- ::Post.permitted_create_params << name if plugin.enabled?+ ::Post.plugin_permitted_create_params[name] = pluginendend@@ -286,27 +294,31 @@ class Plugin::Instanceendend+ # Applies to all sites in a multisite environment. Ignores plugin.enabled?def register_category_custom_field_type(name, type)reloadable_patch do |plugin|- Category.register_custom_field_type(name, type) if plugin.enabled?+ Category.register_custom_field_type(name, type)endend+ # Applies to all sites in a multisite environment. Ignores plugin.enabled?def register_topic_custom_field_type(name, type)reloadable_patch do |plugin|- ::Topic.register_custom_field_type(name, type) if plugin.enabled?+ ::Topic.register_custom_field_type(name, type)endend+ # Applies to all sites in a multisite environment. Ignores plugin.enabled?def register_post_custom_field_type(name, type)reloadable_patch do |plugin|- ::Post.register_custom_field_type(name, type) if plugin.enabled?+ ::Post.register_custom_field_type(name, type)endend+ # Applies to all sites in a multisite environment. Ignores plugin.enabled?def register_group_custom_field_type(name, type)reloadable_patch do |plugin|- ::Group.register_custom_field_type(name, type) if plugin.enabled?+ ::Group.register_custom_field_type(name, type)endend