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:
parent
77b774e7b3
commit
98e62df173
3 changed files with 63 additions and 17 deletions
|
@ -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(
|
||||
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 } }
|
||||
)
|
||||
: this.router.urlFor(`adminPlugins.${plugin.admin_route.location}`);
|
||||
);
|
||||
} 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) {
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue