From cd6fd515fe8ada4878873822fd9295a4bf2a0195 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Fri, 23 Feb 2024 17:04:42 +1000 Subject: [PATCH] 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. --- .../discourse/app/lib/sidebar/admin-sidebar.js | 5 ++++- app/views/safe_mode/index.html.erb | 2 +- plugins/chat/spec/system/admin_sidebar_navigation_spec.rb | 8 ++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js b/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js index 79d26d7e3b7..192b6894d6c 100644 --- a/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js +++ b/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js @@ -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({ diff --git a/app/views/safe_mode/index.html.erb b/app/views/safe_mode/index.html.erb index 070d23d993b..dc7d5f5d8fd 100644 --- a/app/views/safe_mode/index.html.erb +++ b/app/views/safe_mode/index.html.erb @@ -34,7 +34,7 @@

- <%= 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] %> ⚠️ <%= t 'safe_mode.must_select' %> diff --git a/plugins/chat/spec/system/admin_sidebar_navigation_spec.rb b/plugins/chat/spec/system/admin_sidebar_navigation_spec.rb index ccdccf1d752..8505bc7cc1d 100644 --- a/plugins/chat/spec/system/admin_sidebar_navigation_spec.rb +++ b/plugins/chat/spec/system/admin_sidebar_navigation_spec.rb @@ -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!(