2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-08-17 18:04:11 +08:00

FIX: Incorrect site setting link for plugins in admin search (#34349)

In the admin search, links to site settings for plugins that
are not using the new show page for plugins were pointing to
the admin route for the plugin. This is not useful, because most
plugins do not show their site settings here.

Instead, we should link to the plugin category on the
/admin/site_settings
route.
This commit is contained in:
Martin Brennan 2025-08-15 16:31:42 +10:00 committed by GitHub
parent 77b774e7b3
commit 98e62df173
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 63 additions and 17 deletions

View file

@ -175,17 +175,17 @@ export class SettingLinkFormatter {
let url; let url;
if (this.setting.plugin) { if (this.setting.plugin) {
const plugin = this.plugins[this.settingPluginNames[this.setting.plugin]]; const plugin = this.plugins[this.settingPluginNames[this.setting.plugin]];
if (plugin) { const settingPluginCategoryName = this.setting.plugin.replace(/-/g, "_");
url = plugin.admin_route.use_new_show_route
? this.router.urlFor( if (plugin && plugin.admin_route.use_new_show_route) {
`adminPlugins.show.settings`, url = this.router.urlFor(
plugin.admin_route.location, `adminPlugins.show.settings`,
{ queryParams: { filter: this.setting.setting } } plugin.admin_route.location,
) { queryParams: { filter: this.setting.setting } }
: this.router.urlFor(`adminPlugins.${plugin.admin_route.location}`); );
} else { } else {
url = getURL( url = getURL(
`/admin/site_settings/category/all_results?filter=${this.setting.setting}` `/admin/site_settings/category/${settingPluginCategoryName}?filter=${this.setting.setting}`
); );
} }
} else if (this.settingPageMap.areas[this.setting.primary_area]) { } else if (this.settingPageMap.areas[this.setting.primary_area]) {
@ -237,6 +237,18 @@ export default class AdminSearchDataSource extends Service {
}); });
}); });
this.plugins = this.buildPluginsMap();
const allItems = await ajax("/admin/search/all.json");
this.#processSettings(allItems.settings);
this.#processThemesAndComponents(allItems.themes_and_components);
this.#processReports(allItems.reports);
this._mapCached = true;
}
buildPluginsMap() {
const pluginsMap = {};
// TODO (martin) Handle plugin enabling/disabling via MessageBus for this // TODO (martin) Handle plugin enabling/disabling via MessageBus for this
// and the setting list? // and the setting list?
(PreloadStore.get("visiblePlugins") || []).forEach((plugin) => { (PreloadStore.get("visiblePlugins") || []).forEach((plugin) => {
@ -245,15 +257,11 @@ export default class AdminSearchDataSource extends Service {
plugin.enabled && plugin.enabled &&
adminRouteValid(this.router, plugin.admin_route) adminRouteValid(this.router, plugin.admin_route)
) { ) {
this.plugins[plugin.name] = plugin; pluginsMap[plugin.name] = plugin;
} }
}); });
const allItems = await ajax("/admin/search/all.json"); return pluginsMap;
this.#processSettings(allItems.settings);
this.#processThemesAndComponents(allItems.themes_and_components);
this.#processReports(allItems.reports);
this._mapCached = true;
} }
search(filter) { search(filter) {

View file

@ -48,7 +48,16 @@ function fabricateVisiblePlugins() {
{ {
name: "discourse-calendar", name: "discourse-calendar",
humanized_name: "Calendar", humanized_name: "Calendar",
enabled: false, enabled: true,
admin_route: {
auto_generated: false,
// Dummy value so the router works, usually this is `adminPlugins.calendar`
full_location: "adminPlugins.show",
label: "admin.calendar",
// Dummy value so the router works, usually this is `calendar`
location: "index",
use_new_show_route: false,
},
description: description:
"Adds the ability to create a dynamic calendar with events in a topic.", "Adds the ability to create a dynamic calendar with events in a topic.",
}, },
@ -321,7 +330,14 @@ module(
hooks.beforeEach(function () { hooks.beforeEach(function () {
this.router = getOwner(this).lookup("service:router"); this.router = getOwner(this).lookup("service:router");
this.plugins = { chat: fabricateVisiblePlugins()[0] };
const visiblePlugins = fabricateVisiblePlugins();
this.plugins = {
chat: visiblePlugins[0],
"discourse-new-features-feeds": visiblePlugins[1],
"discourse-calendar": visiblePlugins[2],
};
}); });
test("label is correct for a setting that comes from a plugin", async function (assert) { test("label is correct for a setting that comes from a plugin", async function (assert) {
@ -406,6 +422,24 @@ module(
); );
}); });
test("url is correct for a setting that belongs to a plugin not using the new show page", async function (assert) {
let setting = {
plugin: "discourse-calendar",
setting: "calendar_enabled",
};
let formatter = new SettingLinkFormatter(
this.router,
setting,
this.plugins,
{}
);
assert.deepEqual(
formatter.format().url,
"/admin/site_settings/category/discourse_calendar?filter=calendar_enabled",
"url uses the admin site settings category and setting"
);
});
test("url is correct for a setting that has a primary area", async function (assert) { test("url is correct for a setting that has a primary area", async function (assert) {
let setting = { let setting = {
setting: "enable_chat", setting: "enable_chat",

View file

@ -10,6 +10,7 @@ module SiteSettings
cdn cdn
cors cors
cta cta
cx
dm dm
eu eu
faq faq
@ -27,6 +28,7 @@ module SiteSettings
jpg jpg
json json
kb kb
llm
mb mb
oidc oidc
pm pm
@ -35,6 +37,7 @@ module SiteSettings
s3 s3
smtp smtp
svg svg
tei
tl tl
tl0 tl0
tl1 tl1
@ -66,6 +69,7 @@ module SiteSettings
%w[japanese Japanese], %w[japanese Japanese],
%w[linkedin LinkedIn], %w[linkedin LinkedIn],
%w[oauth2 OAuth2], %w[oauth2 OAuth2],
%w[openai OpenAI],
%w[opengraph OpenGraph], %w[opengraph OpenGraph],
["powered by discourse", "Powered by Discourse"], ["powered by discourse", "Powered by Discourse"],
%w[tiktok TikTok], %w[tiktok TikTok],