DEV: Move about_stat_groups to DiscoursePluginRegistry (#20496)

Follow up to 098ab29d4150a5a39880d59ef6cad5f6795a18fd. Since
we just used a `cattr_reader` on `About` this was not safe
for multisite, since some sites could have the chat plugin
enabled and some may not. Using `DiscoursePluginRegistry` gets
around this issue, and makes it so the chat stats only show
for a site if `chat_enabled` is true.
This commit is contained in:
Martin Brennan
2023-03-02 08:10:16 +10:00
committed by GitHub
parent bb0ef4c7b4
commit e195e6f614
5 changed files with 43 additions and 35 deletions

View File

@ -1129,7 +1129,17 @@ class Plugin::Instance
# table. Some stats may be needed purely for reporting purposes and thus
# do not need to be shown in the UI to admins/users.
def register_about_stat_group(plugin_stat_group_name, show_in_ui: false, &block)
About.add_plugin_stat_group(plugin_stat_group_name, show_in_ui: show_in_ui, &block)
# We do not want to register and display the same group multiple times.
if DiscoursePluginRegistry.about_stat_groups.any? { |stat_group|
stat_group[:name] == plugin_stat_group_name
}
return
end
DiscoursePluginRegistry.register_about_stat_group(
{ name: plugin_stat_group_name, show_in_ui: show_in_ui, block: block },
self,
)
end
##