discourse/app/assets/javascripts/admin/addon/controllers/admin-plugins.js
Martin Brennan 2193667e1f
FIX: Plugin JS failing to load would break admin interface (#29139)
If a plugin's JS fails to load for some reason, most commonly
ad blockers, the entire admin interface would break. This is because
we are adding links to the admin routes for plugins that define
them in the sidebar.

We have a fix for this already in the plugin list which shows a warning
to the admin. This fix just prevents the broken link from rendering
in the sidebar if the route is not valid.
2024-10-11 09:26:10 +10:00

39 lines
1.1 KiB
JavaScript

import Controller from "@ember/controller";
import { service } from "@ember/service";
import { adminRouteValid } from "discourse/lib/admin-utilities";
export default class AdminPluginsController extends Controller {
@service adminPluginNavManager;
@service router;
get adminRoutes() {
return this.allAdminRoutes.filter((route) =>
adminRouteValid(this.router, route)
);
}
get brokenAdminRoutes() {
return this.allAdminRoutes.filter(
(route) => !adminRouteValid(this.router, route)
);
}
// NOTE: See also AdminPluginsIndexController, there is some duplication here
// while we convert plugins to use_new_show_route
get allAdminRoutes() {
return this.model
.filter((plugin) => plugin?.enabled && plugin?.adminRoute)
.map((plugin) => {
return Object.assign(plugin.adminRoute, { plugin_id: plugin.id });
});
}
get showTopNav() {
return (
!this.adminPluginNavManager.viewingPluginsList &&
(!this.adminPluginNavManager.currentPlugin ||
this.adminPluginNavManager.isSidebarMode)
);
}
}