From 268d4d4fb9f9b1ecaa1194716ccf0a579c613a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Sat, 21 Dec 2024 01:06:46 +0100 Subject: [PATCH] FIX: more... should not show when there are no visible links (#30405) When lurking on a Discourse as anonymous, if the sidebar is enabled, and a section contains only secondary links that are not visible to anonymous users, we should not display the "more..." button. Otherwise it feels broken because clicking on it does nothing, since there are no "visible" links to be shown. Internal ref t/144716 --- .../sidebar/common/custom-section.gjs | 6 ++-- .../common/community-section/section.js | 6 ++-- ...idebar-anonymous-community-section-test.js | 31 +++++++++++++++++++ spec/serializers/site_serializer_spec.rb | 2 +- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/sidebar/common/custom-section.gjs b/app/assets/javascripts/discourse/app/components/sidebar/common/custom-section.gjs index 6867d6b3101..58f9434092b 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar/common/custom-section.gjs +++ b/app/assets/javascripts/discourse/app/components/sidebar/common/custom-section.gjs @@ -34,9 +34,7 @@ export default class SidebarCustomSection extends Component { if (this.args.sectionData.section_type !== "community") { return new Section(opts); - } - - if (this.currentUser?.admin) { + } else if (this.currentUser?.admin) { return new AdminCommunitySection(opts); } else { return new CommonCommunitySection(opts); @@ -89,7 +87,7 @@ export default class SidebarCustomSection extends Component { @text={{this.section.moreSectionButtonText}} /> {{/if}} - {{else if this.section.moreLinks}} + {{else}} link.shouldDisplay); this.moreLinks = this.section.links .reduce((filtered, link) => { @@ -91,7 +92,8 @@ export default class CommunitySection { return filtered; }, []) - .concat(this.apiSecondaryLinks); + .concat(this.apiSecondaryLinks) + .filter((link) => link.shouldDisplay); } teardown() { diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-community-section-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-community-section-test.js index 41a10506f1f..f47c08bbb68 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-community-section-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-community-section-test.js @@ -83,3 +83,34 @@ acceptance("Sidebar - Anonymous user - Community Section", function (needs) { ); }); }); + +acceptance( + "Sidebar - Anonymous user - Community Section with hidden links", + function (needs) { + needs.settings({ navigation_menu: "sidebar" }); + + needs.site({ + anonymous_sidebar_sections: [ + { + id: 1, + title: "The A Team", + section_type: "community", + links: [ + { + id: 2, + name: "Admin", + value: "/admin", + segment: "secondary", + }, + ], + }, + ], + }); + + test("more... is not shown when there are no displayable links", async function (assert) { + await visit("/"); + + assert.dom(".sidebar-more-section-links-details-summary").doesNotExist(); + }); + } +); diff --git a/spec/serializers/site_serializer_spec.rb b/spec/serializers/site_serializer_spec.rb index c8860e4846d..fc73e12c19e 100644 --- a/spec/serializers/site_serializer_spec.rb +++ b/spec/serializers/site_serializer_spec.rb @@ -214,8 +214,8 @@ RSpec.describe SiteSerializer do it "is not included in the serialised object when user is not anonymous" do guardian = Guardian.new(user) - serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json + expect(serialized).not_to have_key(:anonymous_sidebar_sections) end it "includes only public sidebar sections serialised object when user is anonymous" do