FIX: Prevent admin sidebar errors in safe mode (#25832)

In safe mode plugins are not loaded, so the plugin admin
routes are not loaded. This was causing errors in the
admin sidebar because we are trying to show links to the plugin
admin routes.

This fixes the issue by just not adding the plugin links if
we are in safe mode.
This commit is contained in:
Martin Brennan 2024-02-23 17:04:42 +10:00 committed by GitHub
parent b3238bfc34
commit cd6fd515fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 2 deletions

View File

@ -224,6 +224,7 @@ export default class AdminSidebarPanel extends BaseCustomSidebarPanel {
const siteSettings = getOwnerWithFallback(this).lookup(
"service:site-settings"
);
const session = getOwnerWithFallback(this).lookup("service:session");
if (!currentUser.use_admin_sidebar) {
return [];
}
@ -235,7 +236,9 @@ export default class AdminSidebarPanel extends BaseCustomSidebarPanel {
const savedConfig = this.adminSidebarExperimentStateManager.navConfig;
const navMap = savedConfig || ADMIN_NAV_MAP;
navMap.findBy("name", "plugins").links.push(...pluginAdminRouteLinks());
if (!session.get("safe_mode")) {
navMap.findBy("name", "plugins").links.push(...pluginAdminRouteLinks());
}
if (siteSettings.experimental_form_templates) {
navMap.findBy("name", "customize").links.push({

View File

@ -34,7 +34,7 @@
</p>
<p>
<%= submit_tag t('safe_mode.enter'), class: 'btn btn-danger' %>
<%= submit_tag t('safe_mode.enter'), class: 'btn btn-danger', id: "btn-enter-safe-mode" %>
<%- if flash[:must_select] %>
<span class='safe-mode-warning'>
⚠️ <%= t 'safe_mode.must_select' %>

View File

@ -23,6 +23,14 @@ describe "Admin Revamp | Sidebar Navigation | Plugin Links", type: :system do
expect(sidebar).to have_section_link("Chat", href: "/admin/plugins/chat", count: 1)
end
it "does not show plugin links in the admin sidebar in safe mode" do
visit("/safe-mode")
find("#btn-enter-safe-mode").click
expect(sidebar).to have_section_link("Admin", href: "/admin")
sidebar.click_link_in_section("community", "admin")
expect(sidebar).to have_no_section_link("Chat", href: "/admin/plugins/chat")
end
describe "admin sidebar respects separated and combined sidebar modes" do
it "reverts to always (separated) mode after entering and leaving admin section" do
admin.user_option.update!(