mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 00:32:52 +08:00
FIX: Don’t list values from disabled plugins
Currently, when a plugin registers a new reviewable type or extends a list method (through `register_reviewble_type` and `extend_list_method` respectively), the new array is statically computed and always returns the same value. It will continue to return the same value even if the plugin is disabled (it can be a problem in a multisite env too). To address this issue, this patch changes how `extend_list_method` works. It’s now using `DiscoursePluginRegistry.define_filtered_register` to create a register on the fly and store the extra values from various plugins. It then combines the original values with the ones from the registry. The registry is already aware of disabled plugins, so when a plugin is disabled, its registered values won’t be returned.
This commit is contained in:

committed by
Loïc Guitaut

parent
66878a9e80
commit
5ec227334a
@ -831,14 +831,28 @@ class Plugin::Instance
|
||||
end
|
||||
|
||||
def register_reviewable_type(reviewable_type_class)
|
||||
extend_list_method Reviewable, :types, [reviewable_type_class.name]
|
||||
return unless reviewable_type_class < Reviewable
|
||||
extend_list_method(Reviewable, :types, reviewable_type_class)
|
||||
end
|
||||
|
||||
def extend_list_method(klass, method, new_attributes)
|
||||
current_list = klass.public_send(method)
|
||||
current_list.concat(new_attributes)
|
||||
register_name = [klass, method].join("_").underscore
|
||||
DiscoursePluginRegistry.define_filtered_register(register_name)
|
||||
DiscoursePluginRegistry.public_send(
|
||||
"register_#{register_name.singularize}",
|
||||
new_attributes,
|
||||
self,
|
||||
)
|
||||
|
||||
reloadable_patch { klass.public_send(:define_singleton_method, method) { current_list } }
|
||||
original_method_alias = "__original_#{method}__"
|
||||
return if klass.respond_to?(original_method_alias)
|
||||
reloadable_patch do
|
||||
klass.singleton_class.alias_method(original_method_alias, method)
|
||||
klass.define_singleton_method(method) do
|
||||
public_send(original_method_alias) |
|
||||
DiscoursePluginRegistry.public_send(register_name).flatten
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def directory_name
|
||||
|
Reference in New Issue
Block a user