A platform for community discussion. Free, open, simple.
DEV: adds const ALL_PAGES_EXCLUDED_ROUTES (#34522)
Yuriy Kurant5128e6d1edc4
diff --git a/app/assets/javascripts/discourse/app/components/header/contents.gjs b/app/assets/javascripts/discourse/app/components/header/contents.gjsindex a74425be427..b58d74d64de 100644--- a/app/assets/javascripts/discourse/app/components/header/contents.gjs+++ b/app/assets/javascripts/discourse/app/components/header/contents.gjs@@ -1,6 +1,7 @@import Component from "@glimmer/component";import { service } from "@ember/service";import { and } from "truth-helpers";+import { ALL_PAGES_EXCLUDED_ROUTES } from "discourse/components/welcome-banner";import deprecatedOutletArgument from "discourse/helpers/deprecated-outlet-argument";import lazyHash from "discourse/helpers/lazy-hash";import { applyValueTransformer } from "discourse/lib/transformer";@@ -41,17 +42,12 @@ export default class Contents extends Component {}get showHeaderSearch() {- const hideForRoutes = [- "signup",- "login",- "invites.show",- "activate-account",- ];-if (this.site.mobileView ||this.args.narrowDesktop ||- hideForRoutes.some((name) => name === this.router.currentRouteName) ||+ ALL_PAGES_EXCLUDED_ROUTES.some(+ (name) => name === this.router.currentRouteName+ ) ||this.search.welcomeBannerSearchInViewport) {return false;diff --git a/app/assets/javascripts/discourse/app/components/welcome-banner.gjs b/app/assets/javascripts/discourse/app/components/welcome-banner.gjsindex 871bf84dc36..7606823de0c 100644--- a/app/assets/javascripts/discourse/app/components/welcome-banner.gjs+++ b/app/assets/javascripts/discourse/app/components/welcome-banner.gjs@@ -13,6 +13,14 @@ import { sanitize } from "discourse/lib/text";import { defaultHomepage, escapeExpression } from "discourse/lib/utilities";import I18n, { i18n } from "discourse-i18n";+export const ALL_PAGES_EXCLUDED_ROUTES = [+ "activate-account",+ "invites.show",+ "login",+ "password-reset",+ "signup",+];+export default class WelcomeBanner extends Component {@service router;@service siteSettings;@@ -51,22 +59,26 @@ export default class WelcomeBanner extends Component {});get displayForRoute() {- switch (this.siteSettings.welcome_banner_page_visibility) {+ const { currentRouteName } = this.router;+ const { top_menu, welcome_banner_page_visibility } = this.siteSettings;++ switch (welcome_banner_page_visibility) {case "top_menu_pages":- return this.siteSettings.top_menu+ return top_menu.split("|")- .any(- (menuItem) =>- `discovery.${menuItem}` === this.router.currentRouteName- );+ .any((menuItem) => `discovery.${menuItem}` === currentRouteName);case "homepage":- return (- this.router.currentRouteName === `discovery.${defaultHomepage()}`- );+ return currentRouteName === `discovery.${defaultHomepage()}`;case "discovery":- return this.router.currentRouteName.startsWith("discovery.");+ return currentRouteName.startsWith("discovery.");case "all_pages":- return true;+ return (+ currentRouteName !== "full-page-search" &&+ !currentRouteName.startsWith("admin.") &&+ !ALL_PAGES_EXCLUDED_ROUTES.some(+ (routeName) => routeName === currentRouteName+ )+ );default:return false;}diff --git a/spec/system/welcome_banner_spec.rb b/spec/system/welcome_banner_spec.rbindex 419aa092cf5..1e9206a204c 100644--- a/spec/system/welcome_banner_spec.rb+++ b/spec/system/welcome_banner_spec.rb@@ -185,16 +185,53 @@ describe "Welcome banner", type: :system docontext "with interface page visibility setting" dobefore { current_user.update!(admin: true) }- it "should show on all pages" do- SiteSetting.welcome_banner_page_visibility = "all_pages"+ context "when show on all pages" do+ fab!(:invite)+ let(:inactive_user_email_token) do+ Fabricate(:email_token, user: Fabricate(:user, active: false))+ end+ let(:password_reset_email_token) do+ current_user.email_tokens.create!(+ email: current_user.email,+ scope: EmailToken.scopes[:password_reset],+ )+ end- visit "/"- expect(banner).to be_visible- sign_in(current_user)- %W[/ /u/#{current_user.username}/preferences/emails /my/messages].each do |path|- visit path+ before { SiteSetting.welcome_banner_page_visibility = "all_pages" }++ it "should show on" do+ sign_in(current_user)++ visit "/"+ expect(banner).to be_visible++ visit "/u/#{current_user.username}/preferences/emails"+ expect(banner).to be_visible++ visit "/my/messages"expect(banner).to be_visibleend++ it "should NOT show on" do+ visit "/login"+ expect(banner).to be_hidden++ visit "/signup"+ expect(banner).to be_hidden++ visit "/invites/#{invite.invite_key}"+ expect(banner).to be_hidden++ visit "/u/activate-account/#{inactive_user_email_token}"+ expect(banner).to be_hidden++ sign_in(current_user)+ visit "/u/password-reset/#{password_reset_email_token}"+ expect(banner).to be_hidden++ visit "/admin"+ expect(banner).to be_hidden+ endendit "should show on discovery routes only" do