mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 20:41:24 +08:00
This reverts commit 4895e76ef797127ce45b33ba3a9a2174293ce9d8.
This commit is contained in:
@ -109,27 +109,7 @@ class Plugin::Instance
|
||||
|
||||
delegate :name, to: :metadata
|
||||
|
||||
def add_to_serializer(
|
||||
serializer,
|
||||
attr,
|
||||
deprecated_respect_plugin_enabled = nil,
|
||||
respect_plugin_enabled: true,
|
||||
include_condition: nil,
|
||||
&block
|
||||
)
|
||||
if !deprecated_respect_plugin_enabled.nil?
|
||||
Discourse.deprecate(
|
||||
"add_to_serializer's respect_plugin_enabled argument should be passed as a keyword argument",
|
||||
)
|
||||
respect_plugin_enabled = deprecated_respect_plugin_enabled
|
||||
end
|
||||
|
||||
if attr.to_s.starts_with?("include_")
|
||||
Discourse.deprecate(
|
||||
"add_to_serializer should not be used to directly override include_*? methods. Use the include_condition keyword argument instead",
|
||||
)
|
||||
end
|
||||
|
||||
def add_to_serializer(serializer, attr, define_include_method = true, &block)
|
||||
reloadable_patch do |plugin|
|
||||
base =
|
||||
begin
|
||||
@ -143,13 +123,9 @@ class Plugin::Instance
|
||||
unless attr.to_s.start_with?("include_")
|
||||
klass.attributes(attr)
|
||||
|
||||
if respect_plugin_enabled || include_condition
|
||||
if define_include_method
|
||||
# Don't include serialized methods if the plugin is disabled
|
||||
klass.public_send(:define_method, "include_#{attr}?") do
|
||||
next false if respect_plugin_enabled && !plugin.enabled?
|
||||
next instance_exec(&include_condition) if include_condition
|
||||
true
|
||||
end
|
||||
klass.public_send(:define_method, "include_#{attr}?") { plugin.enabled? }
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user