mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 01:34:13 +08:00
2193667e1f
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.
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
import Controller from "@ember/controller";
|
|
import { action } from "@ember/object";
|
|
import { service } from "@ember/service";
|
|
import { adminRouteValid } from "discourse/lib/admin-utilities";
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
|
import SiteSetting from "admin/models/site-setting";
|
|
|
|
export default class AdminPluginsIndexController extends Controller {
|
|
@service session;
|
|
@service adminPluginNavManager;
|
|
@service router;
|
|
|
|
@action
|
|
async togglePluginEnabled(plugin) {
|
|
const oldValue = plugin.enabled;
|
|
const newValue = !oldValue;
|
|
|
|
try {
|
|
plugin.enabled = newValue;
|
|
await SiteSetting.update(plugin.enabledSetting, newValue);
|
|
this.session.requiresRefresh = true;
|
|
} catch (e) {
|
|
plugin.enabled = oldValue;
|
|
popupAjaxError(e);
|
|
}
|
|
}
|
|
|
|
// NOTE: See also AdminPluginsController, there is some duplication here
|
|
// while we convert plugins to use_new_show_route
|
|
get adminRoutes() {
|
|
return this.allAdminRoutes.filter((route) =>
|
|
adminRouteValid(this.router, route)
|
|
);
|
|
}
|
|
|
|
get allAdminRoutes() {
|
|
return this.model
|
|
.filter((plugin) => plugin?.enabled && plugin?.adminRoute)
|
|
.map((plugin) => {
|
|
return Object.assign(plugin.adminRoute, { plugin_id: plugin.id });
|
|
});
|
|
}
|
|
}
|