discourse/app/controllers/admin/plugins_controller.rb
Osama Sayegh 3b86dee520
FIX: Don't allow access to plugin page if plugin is not visible (#26431)
Plugins that are hidden or disabled aren't shown in the plugins list at `/admin/plugins` because they cannot be changed. However, the `#show` route doesn't check for the plugin's state and responds with 200 and the plugin's info even if the plugin is hidden or disabled. This commit makes the `#show` route respond with 404 if the plugin is hidden or disabled.
2024-04-02 16:26:15 +03:00

24 lines
642 B
Ruby

# frozen_string_literal: true
class Admin::PluginsController < Admin::StaffController
def index
render_serialized(
Discourse.plugins_sorted_by_name(enabled_only: false),
AdminPluginSerializer,
root: "plugins",
)
end
def show
plugin = Discourse.plugins_by_name[params[:plugin_id]]
# An escape hatch in case a plugin is using an un-prefixed
# version of their plugin name for a route.
plugin = Discourse.plugins_by_name["discourse-#{params[:plugin_id]}"] if !plugin
raise Discourse::NotFound if !plugin&.visible?
render_serialized(plugin, AdminPluginSerializer, root: nil)
end
end