A platform for community discussion. Free, open, simple.
FIX: Respect homepage prefs on admin sidebar Back to Forum link (#25642)
Martin Brennan5935148bd863
diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js b/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.jsindex 1931c892b1f..5d7a221d047 100644--- a/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js+++ b/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js@@ -4,6 +4,7 @@ import BaseCustomSidebarPanel from "discourse/lib/sidebar/base-custom-sidebar-paimport BaseCustomSidebarSection from "discourse/lib/sidebar/base-custom-sidebar-section";import BaseCustomSidebarSectionLink from "discourse/lib/sidebar/base-custom-sidebar-section-link";import { ADMIN_PANEL } from "discourse/lib/sidebar/panels";+import { defaultHomepage } from "discourse/lib/utilities";import { getOwnerWithFallback } from "discourse-common/lib/get-owner";import I18n from "discourse-i18n";@@ -109,7 +110,7 @@ export function useAdminNavConfig(navMap) {links: [{name: "back_to_forum",- route: "discovery.latest",+ route: `discovery.${defaultHomepage()}`,label: "admin.back_to_forum",icon: "arrow-left",},diff --git a/app/models/user_option.rb b/app/models/user_option.rbindex b62b2d42431..ef3a9a6a03e 100644--- a/app/models/user_option.rb+++ b/app/models/user_option.rb@@ -1,6 +1,16 @@# frozen_string_literal: trueclass UserOption < ActiveRecord::Base+ HOMEPAGES = {+ 1 => "latest",+ 2 => "categories",+ 3 => "unread",+ 4 => "new",+ 5 => "top",+ 6 => "bookmarks",+ 7 => "unseen",+ }+self.ignored_columns = ["disable_jump_reply", # Remove once 20210706091905 is promoted from post_deploy to regular migration"sidebar_list_destination", # TODO(osama): Remove in January 2024@@ -170,30 +180,11 @@ class UserOption < ActiveRecord::Baseenddef homepage- case homepage_id- when 1- "latest"- when 2- "categories"- when 3- "unread"- when 4- "new"- when 5- "top"- when 6- "bookmarks"- when 7- "unseen"- when 8- if SiteSetting.experimental_hot_topics- "hot"- else- SiteSetting.homepage- end- else- SiteSetting.homepage- end+ return HOMEPAGES[homepage_id] if HOMEPAGES.keys.include?(homepage_id)++ return SiteSetting.experimental_hot_topics ? "hot" : SiteSetting.homepage if homepage_id == 8++ SiteSetting.homepageenddef text_sizediff --git a/spec/system/admin_revamp_sidebar_navigation_spec.rb b/spec/system/admin_revamp_sidebar_navigation_spec.rbindex 070c0d0d773..1f4a4ed1964 100644--- a/spec/system/admin_revamp_sidebar_navigation_spec.rb+++ b/spec/system/admin_revamp_sidebar_navigation_spec.rb@@ -24,6 +24,14 @@ describe "Admin Revamp | Sidebar Navigation", type: :system doexpect(sidebar).to have_no_section("admin-nav-section-root")end+ it "respects the user homepage preference for the Back to Forum link" do+ admin.user_option.update!(+ homepage_id: UserOption::HOMEPAGES.find { |id, value| value == "categories" }.first,+ )+ visit("/admin")+ expect(page).to have_link("Back to Forum", href: "/categories")+ end+context "when on mobile" doit "shows the admin sidebar links in the header-dropdown when navigating to an admin route and hides them when leaving",mobile: true do