Skip to content

A platform for community discussion. Free, open, simple.

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

Martin Brennan98e62df1733b
diff --git a/app/assets/javascripts/admin/addon/services/admin-search-data-source.js b/app/assets/javascripts/admin/addon/services/admin-search-data-source.js
index c75eadae560..02eeeaef8e3 100644
--- a/app/assets/javascripts/admin/addon/services/admin-search-data-source.js
+++ b/app/assets/javascripts/admin/addon/services/admin-search-data-source.js
@@ -175,17 +175,17 @@ export class SettingLinkFormatter {
let url;
if (this.setting.plugin) {
const plugin = this.plugins[this.settingPluginNames[this.setting.plugin]];
- if (plugin) {
- url = plugin.admin_route.use_new_show_route
- ? this.router.urlFor(
- `adminPlugins.show.settings`,
- plugin.admin_route.location,
- { queryParams: { filter: this.setting.setting } }
- )
- : this.router.urlFor(`adminPlugins.${plugin.admin_route.location}`);
+ const settingPluginCategoryName = this.setting.plugin.replace(/-/g, "_");
+
+ if (plugin && plugin.admin_route.use_new_show_route) {
+ url = this.router.urlFor(
+ `adminPlugins.show.settings`,
+ plugin.admin_route.location,
+ { queryParams: { filter: this.setting.setting } }
+ );
} else {
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]) {
@@ -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
// and the setting list?
(PreloadStore.get("visiblePlugins") || []).forEach((plugin) => {
@@ -245,15 +257,11 @@ export default class AdminSearchDataSource extends Service {
plugin.enabled &&
adminRouteValid(this.router, plugin.admin_route)
) {
- this.plugins[plugin.name] = plugin;
+ pluginsMap[plugin.name] = plugin;
}
});
- 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;
+ return pluginsMap;
}
search(filter) {
diff --git a/app/assets/javascripts/discourse/tests/unit/services/admin-search-data-source-test.js b/app/assets/javascripts/discourse/tests/unit/services/admin-search-data-source-test.js
index cf3048ccf54..4f83bfc1d88 100644
--- a/app/assets/javascripts/discourse/tests/unit/services/admin-search-data-source-test.js
+++ b/app/assets/javascripts/discourse/tests/unit/services/admin-search-data-source-test.js
@@ -48,7 +48,16 @@ function fabricateVisiblePlugins() {
{
name: "discourse-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:
"Adds the ability to create a dynamic calendar with events in a topic.",
},
@@ -321,7 +330,14 @@ module(
hooks.beforeEach(function () {
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) {
@@ -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) {
let setting = {
setting: "enable_chat",
diff --git a/lib/site_settings/label_formatter.rb b/lib/site_settings/label_formatter.rb
index 339b6b99f8b..9485c768524 100644
--- a/lib/site_settings/label_formatter.rb
+++ b/lib/site_settings/label_formatter.rb
@@ -10,6 +10,7 @@ module SiteSettings
cdn
cors
cta
+ cx
dm
eu
faq
@@ -27,6 +28,7 @@ module SiteSettings
jpg
json
kb
+ llm
mb
oidc
pm
@@ -35,6 +37,7 @@ module SiteSettings
s3
smtp
svg
+ tei
tl
tl0
tl1
@@ -66,6 +69,7 @@ module SiteSettings
%w[japanese Japanese],
%w[linkedin LinkedIn],
%w[oauth2 OAuth2],
+ %w[openai OpenAI],
%w[opengraph OpenGraph],
["powered by discourse", "Powered by Discourse"],
%w[tiktok TikTok],