A platform for community discussion. Free, open, simple.
FIX: Sidebar messages link updates (#33444)
Yuriy Kurantba64209468a2
diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/common/community-section/section.js b/app/assets/javascripts/discourse/app/lib/sidebar/common/community-section/section.jsindex ecd4cf2a10d..3fe4387a292 100644--- a/app/assets/javascripts/discourse/app/lib/sidebar/common/community-section/section.js+++ b/app/assets/javascripts/discourse/app/lib/sidebar/common/community-section/section.js@@ -14,6 +14,7 @@ import {import SectionLink from "discourse/lib/sidebar/section-link";import AdminSectionLink from "discourse/lib/sidebar/user/community-section/admin-section-link";import InviteSectionLink from "discourse/lib/sidebar/user/community-section/invite-section-link";+import MyMessagesSectionLink from "discourse/lib/sidebar/user/community-section/my-messages-section-link";import MyPostsSectionLink from "discourse/lib/sidebar/user/community-section/my-posts-section-link";import ReviewSectionLink from "discourse/lib/sidebar/user/community-section/review-section-link";@@ -23,6 +24,7 @@ const SPECIAL_LINKS_MAP = {"/u": UsersSectionLink,"/faq": FAQSectionLink,"/my/activity": MyPostsSectionLink,+ "/my/messages": MyMessagesSectionLink,"/review": ReviewSectionLink,"/badges": BadgesSectionLink,"/admin": AdminSectionLink,diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/user/community-section/my-messages-section-link.js b/app/assets/javascripts/discourse/app/lib/sidebar/user/community-section/my-messages-section-link.jsnew file mode 100644index 00000000000..70f018095d8--- /dev/null+++ b/app/assets/javascripts/discourse/app/lib/sidebar/user/community-section/my-messages-section-link.js@@ -0,0 +1,35 @@+import BaseSectionLink from "discourse/lib/sidebar/base-community-section-link";+import { i18n } from "discourse-i18n";++export default class MyMessagesSectionLink extends BaseSectionLink {+ get name() {+ return "my-messages";+ }++ get route() {+ return "userPrivateMessages.user";+ }++ get model() {+ return this.currentUser;+ }++ get title() {+ return i18n("sidebar.sections.community.links.my_messages.content");+ }++ get text() {+ return i18n(+ `sidebar.sections.community.links.${this.overridenName.toLowerCase()}.content`,+ { defaultValue: this.overridenName }+ );+ }++ get shouldDisplay() {+ return this.currentUser?.can_send_private_messages;+ }++ get currentWhen() {+ return "userPrivateMessages";+ }+}diff --git a/app/assets/javascripts/discourse/tests/fixtures/session-fixtures.js b/app/assets/javascripts/discourse/tests/fixtures/session-fixtures.jsindex 728ee8c6d62..d8e137f6725 100644--- a/app/assets/javascripts/discourse/tests/fixtures/session-fixtures.js+++ b/app/assets/javascripts/discourse/tests/fixtures/session-fixtures.js@@ -91,7 +91,7 @@ export default {},{id: 333,- name: "My Posts",+ name: "My posts",value: "/my/activity",icon: "user",external: false,diff --git a/app/assets/javascripts/discourse/tests/fixtures/site-fixtures.js b/app/assets/javascripts/discourse/tests/fixtures/site-fixtures.jsindex 932712acc7c..30561138e4e 100644--- a/app/assets/javascripts/discourse/tests/fixtures/site-fixtures.js+++ b/app/assets/javascripts/discourse/tests/fixtures/site-fixtures.js@@ -793,7 +793,7 @@ export default {},{id: 333,- name: "My Posts",+ name: "My posts",value: "/my/activity",icon: "user",external: false,diff --git a/app/models/sidebar_url.rb b/app/models/sidebar_url.rbindex cd9b4bc3962..8ac94b57335 100644--- a/app/models/sidebar_url.rb+++ b/app/models/sidebar_url.rb@@ -14,13 +14,13 @@ class SidebarUrl < ActiveRecord::Basesegment: SidebarUrl.segments["primary"],},{- name: "My Posts",+ name: "My posts",path: "/my/activity",icon: "user",segment: SidebarUrl.segments["primary"],},{- name: "My Messages",+ name: "My messages",path: "/my/messages",icon: "inbox",segment: SidebarUrl.segments["primary"],diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 4488d40e2b9..b7e155b0f89 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -4634,7 +4634,7 @@ en:new_new:help: "topics created or replied to in the last few days"posted:- title: "My Posts"+ title: "My posts"help: "topics you have posted in"bookmarks:title: "Bookmarks"@@ -5181,8 +5181,8 @@ en:content: "Users"title: "List of all users"my_posts:- content: "My Posts"- content_drafts: "My Drafts"+ content: "My posts"+ content_drafts: "My drafts"title: "My recent topic activity"title_drafts: "My unposted drafts"draft_count:@@ -5198,7 +5198,7 @@ en:content: "Invite"title: "Invite new members"my_messages:- content: "My Messages"+ content: "My messages"title: "My personal messages"global_section: "Global section, visible to everyone"panels:diff --git a/db/migrate/20250702133530_fix_capitalisation_in_sidebar_urls.rb b/db/migrate/20250702133530_fix_capitalisation_in_sidebar_urls.rbnew file mode 100644index 00000000000..4058abad5c2--- /dev/null+++ b/db/migrate/20250702133530_fix_capitalisation_in_sidebar_urls.rb@@ -0,0 +1,18 @@+# frozen_string_literal: true+class FixCapitalisationInSidebarUrls < ActiveRecord::Migration[7.2]+ def up+ execute <<~SQL+ UPDATE sidebar_urls+ SET name = CASE+ WHEN name = 'My Messages' THEN 'My messages'+ WHEN name = 'My Posts' THEN 'My posts'+ ELSE name+ END+ WHERE name IN ('My Messages', 'My Posts');+ SQL+ end++ def down+ raise ActiveRecord::IrreversibleMigration+ end+enddiff --git a/spec/models/sidebar_section_spec.rb b/spec/models/sidebar_section_spec.rbindex 14319b42774..e7295b2c861 100644--- a/spec/models/sidebar_section_spec.rb+++ b/spec/models/sidebar_section_spec.rb@@ -24,8 +24,8 @@ RSpec.describe SidebarSection doexpect(community_section.sidebar_section_links.all.map { |link| link.linkable.name }).to eq(["Topics",- "My Posts",- "My Messages",+ "My posts",+ "My messages","Review","Admin","Invite",diff --git a/spec/requests/admin/config/site_settings_controller_spec.rb b/spec/requests/admin/config/site_settings_controller_spec.rbindex ffb265830aa..6a280daca6c 100644--- a/spec/requests/admin/config/site_settings_controller_spec.rb+++ b/spec/requests/admin/config/site_settings_controller_spec.rb@@ -64,7 +64,7 @@ RSpec.describe Admin::SiteSettingsController do)end- xit "returns site settings by area" do+ it "returns site settings by area" doget "/admin/config/site_settings.json", params: { filter_area: "flags" }expect(response.status).to eq(200)expect(response.parsed_body["site_settings"].map { |s| s["setting"] }).to match_array(diff --git a/spec/requests/sidebar_sections_controller_spec.rb b/spec/requests/sidebar_sections_controller_spec.rbindex e55549383d6..75d5847e1f3 100644--- a/spec/requests/sidebar_sections_controller_spec.rb+++ b/spec/requests/sidebar_sections_controller_spec.rb@@ -344,7 +344,7 @@ RSpec.describe SidebarSectionsController dosign_in(admin)topics_link = community_section.sidebar_urls.find_by(name: "Topics")- my_posts_link = community_section.sidebar_urls.find_by(name: "My Posts")+ my_posts_link = community_section.sidebar_urls.find_by(name: "My posts")community_section.sidebar_section_linksdiff --git a/spec/system/editing_sidebar_community_section_spec.rb b/spec/system/editing_sidebar_community_section_spec.rbindex 7d439d667bc..de046ef6e46 100644--- a/spec/system/editing_sidebar_community_section_spec.rb+++ b/spec/system/editing_sidebar_community_section_spec.rb@@ -35,7 +35,7 @@ RSpec.describe "Editing Sidebar Community Section", type: :system dopage.refreshexpect(sidebar.primary_section_links("community")).to eq(- ["My Posts", "Topics", "Review", "Admin", "Invite", "More"],+ ["My posts", "Topics", "Review", "Admin", "Invite", "More"],)expect(sidebar.primary_section_icons("community")).to eq(@@ -48,7 +48,7 @@ RSpec.describe "Editing Sidebar Community Section", type: :system doexpect(sidebar).to have_section("Community")expect(sidebar.primary_section_links("community")).to eq(- ["Topics", "My Posts", "Review", "Admin", "Invite", "More"],+ ["Topics", "My posts", "Review", "Admin", "Invite", "More"],)expect(sidebar.primary_section_icons("community")).to eq(diff --git a/spec/system/page_objects/components/navigation_menu/sidebar.rb b/spec/system/page_objects/components/navigation_menu/sidebar.rbindex 90ee1bcd154..0c6ade79739 100644--- a/spec/system/page_objects/components/navigation_menu/sidebar.rb+++ b/spec/system/page_objects/components/navigation_menu/sidebar.rb@@ -73,6 +73,24 @@ module PageObjectsdef click_search_inputpage.find(".sidebar-search__input").clickend++ def my_messages+ I18n.t("js.sidebar.sections.community.links.my_messages.content")+ end++ def has_my_messages_link?+ page.has_css?(+ ".sidebar-section-link[data-link-name='#{my_messages.downcase.parameterize}']",+ text: my_messages,+ )+ end++ def has_no_my_messages_link?+ page.has_no_css?(+ ".sidebar-section-link[data-link-name='#{my_messages.downcase.parameterize}']",+ text: my_messages,+ )+ endendendenddiff --git a/spec/system/viewing_sidebar_spec.rb b/spec/system/viewing_sidebar_spec.rbindex 7f70fc7ae0e..03e4c9bdab2 100644--- a/spec/system/viewing_sidebar_spec.rb+++ b/spec/system/viewing_sidebar_spec.rb@@ -1,174 +1,200 @@# frozen_string_literal: true-describe "Viewing sidebar as logged in user", type: :system do- fab!(:admin)- fab!(:user)- fab!(:category_sidebar_section_link) { Fabricate(:category_sidebar_section_link, user: user) }-+describe "Viewing sidebar", type: :system dolet(:sidebar) { PageObjects::Components::NavigationMenu::Sidebar.new }- before { sign_in(user) }+ context "as logged in user", type: :system do+ fab!(:admin) { Fabricate(:admin, refresh_auto_groups: true) }+ fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }+ fab!(:category_sidebar_section_link) { Fabricate(:category_sidebar_section_link, user: user) }- describe "when using the header dropdown navigation menu" do- before { SiteSetting.navigation_menu = "header dropdown" }+ before { sign_in(user) }- it "should display the sidebar when `navigation_menu` query param is 'sidebar' and maintain header dropdown" do- visit("/latest?navigation_menu=sidebar")+ describe "when using the header dropdown navigation menu" do+ before { SiteSetting.navigation_menu = "header dropdown" }- expect(sidebar).to be_visible- expect(page).to have_css(".hamburger-dropdown")+ it "should display the sidebar when `navigation_menu` query param is 'sidebar' and maintain header dropdown" do+ visit("/latest?navigation_menu=sidebar")++ expect(sidebar).to be_visible+ expect(page).to have_css(".hamburger-dropdown")+ endend- end- describe "when using the sidebar navigation menu" do- before { SiteSetting.navigation_menu = "sidebar" }+ describe "when using the sidebar navigation menu" do+ before { SiteSetting.navigation_menu = "sidebar" }- it "should display the sidebar dropdown menu when `navigation_menu` query param is 'header_dropdown'" do- visit("/latest?navigation_menu=header_dropdown")+ it "should display the sidebar dropdown menu when `navigation_menu` query param is 'header_dropdown'" do+ visit("/latest?navigation_menu=header_dropdown")- expect(sidebar).to be_not_visible+ expect(sidebar).to be_not_visible- header_dropdown = PageObjects::Components::SidebarHeaderDropdown.new- header_dropdown.click+ header_dropdown = PageObjects::Components::SidebarHeaderDropdown.new+ header_dropdown.click- expect(header_dropdown).to be_visible+ expect(header_dropdown).to be_visible+ endend- end- describe "Community sidebar section", type: :system do- fab!(:user) { Fabricate(:user, locale: "pl_PL") }- fab!(:translation_override) do- TranslationOverride.create!(- locale: "pl_PL",- translation_key: "js.sidebar.sections.community.links.topics.content",- value: "Tematy",- )- TranslationOverride.create!(- locale: "pl_PL",- translation_key: "js.sidebar.sections.community.links.topics.title",- value: "Wszystkie tematy",- )- end+ describe "Community sidebar section", type: :system do+ fab!(:user) { Fabricate(:user, locale: "pl_PL") }+ fab!(:translation_override) do+ TranslationOverride.create!(+ locale: "pl_PL",+ translation_key: "js.sidebar.sections.community.links.topics.content",+ value: "Tematy",+ )+ TranslationOverride.create!(+ locale: "pl_PL",+ translation_key: "js.sidebar.sections.community.links.topics.title",+ value: "Wszystkie tematy",+ )+ end- before { SiteSetting.allow_user_locale = true }+ before { SiteSetting.allow_user_locale = true }- it "has correct translations" do- sign_in user- visit("/latest")- links = page.all("#sidebar-section-content-community .sidebar-section-link-wrapper a")- expect(links.map(&:text)[0]).to eq("Tematy")- expect(links.map { |link| link[:title] }[0]).to eq("Wszystkie tematy")+ it "has correct translations" do+ sign_in user+ visit("/latest")+ links = page.all("#sidebar-section-content-community .sidebar-section-link-wrapper a")+ expect(links.map(&:text)[0]).to eq("Tematy")+ expect(links.map { |link| link[:title] }[0]).to eq("Wszystkie tematy")+ endend- end- describe "when viewing the 'more' content in the Community sidebar section" do- let(:more_trigger_selector) do- ".sidebar-section[data-section-name='community'] .sidebar-more-section-trigger"- end- let(:more_links_selector) do- ".sidebar-section[data-section-name='community'] .sidebar-more-section-content"- end+ describe "when viewing the 'more' content in the Community sidebar section" do+ let(:more_trigger_selector) do+ ".sidebar-section[data-section-name='community'] .sidebar-more-section-trigger"+ end+ let(:more_links_selector) do+ ".sidebar-section[data-section-name='community'] .sidebar-more-section-content"+ end- it "toggles the more menu and handles click outside to close it" do- visit("/latest")+ it "toggles the more menu and handles click outside to close it" do+ visit("/latest")- find(more_trigger_selector).click+ find(more_trigger_selector).click- expect(page).to have_selector(more_links_selector, visible: true)+ expect(page).to have_selector(more_links_selector, visible: true)- expect(page).to have_selector("#{more_trigger_selector}[aria-expanded='true']")+ expect(page).to have_selector("#{more_trigger_selector}[aria-expanded='true']")- find(more_trigger_selector).click+ find(more_trigger_selector).click- expect(page).not_to have_selector(more_links_selector)+ expect(page).not_to have_selector(more_links_selector)- expect(page).to have_selector("#{more_trigger_selector}[aria-expanded='false']")+ expect(page).to have_selector("#{more_trigger_selector}[aria-expanded='false']")- find(more_trigger_selector).click+ find(more_trigger_selector).click- find(".d-header-wrap").click+ find(".d-header-wrap").click- expect(page).not_to have_selector(more_links_selector)+ expect(page).not_to have_selector(more_links_selector)+ endend- end- describe "when viewing the tags section" do- fab!(:tag1) do- Fabricate(:tag, name: "tag 1", description: "tag 1 description <script>").tap do |tag|- Fabricate.times(1, :topic, tags: [tag])+ describe "when viewing the tags section" do+ fab!(:tag1) do+ Fabricate(:tag, name: "tag 1", description: "tag 1 description <script>").tap do |tag|+ Fabricate.times(1, :topic, tags: [tag])+ endend- end- fab!(:tag2) do- Fabricate(:tag, name: "tag 2").tap { |tag| Fabricate.times(2, :topic, tags: [tag]) }- end+ fab!(:tag2) do+ Fabricate(:tag, name: "tag 2").tap { |tag| Fabricate.times(2, :topic, tags: [tag]) }+ end- fab!(:tag3) do- Fabricate(:tag, name: "tag 3", description: "tag 3 description").tap do |tag|- Fabricate.times(3, :topic, tags: [tag])+ fab!(:tag3) do+ Fabricate(:tag, name: "tag 3", description: "tag 3 description").tap do |tag|+ Fabricate.times(3, :topic, tags: [tag])+ endend- end- fab!(:tag4) do- Fabricate(:tag, name: "tag 4").tap { |tag| Fabricate.times(2, :topic, tags: [tag]) }- end+ fab!(:tag4) do+ Fabricate(:tag, name: "tag 4").tap { |tag| Fabricate.times(2, :topic, tags: [tag]) }+ end- fab!(:tag5) do- Fabricate(:tag, name: "tag 5").tap { |tag| Fabricate.times(2, :topic, tags: [tag]) }- end+ fab!(:tag5) do+ Fabricate(:tag, name: "tag 5").tap { |tag| Fabricate.times(2, :topic, tags: [tag]) }+ end- fab!(:tag6) do- Fabricate(:tag, name: "tag 6").tap { |tag| Fabricate.times(1, :topic, tags: [tag]) }- end+ fab!(:tag6) do+ Fabricate(:tag, name: "tag 6").tap { |tag| Fabricate.times(1, :topic, tags: [tag]) }+ end- it "should not display the tags section when tagging is disabled" do- SiteSetting.tagging_enabled = false+ it "should not display the tags section when tagging is disabled" do+ SiteSetting.tagging_enabled = false- visit("/latest")+ visit("/latest")- expect(sidebar).to be_visible- expect(sidebar).to have_no_tags_section- end+ expect(sidebar).to be_visible+ expect(sidebar).to have_no_tags_section+ end- it "should not display the tags section when there are no tags that a user can see" do- Tag.delete_all+ it "should not display the tags section when there are no tags that a user can see" do+ Tag.delete_all- visit("/latest")+ visit("/latest")- expect(sidebar).to be_visible- expect(sidebar).to have_no_tags_section- end+ expect(sidebar).to be_visible+ expect(sidebar).to have_no_tags_section+ end- it "should display the site's top tags in the tags section when user has not configured any tags" do- visit("/latest")+ it "should display the site's top tags in the tags section when user has not configured any tags" do+ visit("/latest")- expect(sidebar).to be_visible- expect(sidebar).to have_tags_section- expect(sidebar).to have_tag_section_links([tag3, tag2, tag4, tag5, tag1])- expect(sidebar).to have_tag_section_link_with_title(tag3, "tag 3 description")- expect(sidebar).to have_tag_section_link_with_title(tag1, "tag 1 description ")- expect(sidebar).to have_all_tags_section_link+ expect(sidebar).to be_visible+ expect(sidebar).to have_tags_section+ expect(sidebar).to have_tag_section_links([tag3, tag2, tag4, tag5, tag1])+ expect(sidebar).to have_tag_section_link_with_title(tag3, "tag 3 description")+ expect(sidebar).to have_tag_section_link_with_title(tag1, "tag 1 description ")+ expect(sidebar).to have_all_tags_section_link+ end++ it "should display the tags configured by the user in alphabetical order" do+ Fabricate(:sidebar_section_link, linkable: tag3, user: user)+ Fabricate(:sidebar_section_link, linkable: tag1, user: user)+ Fabricate(:sidebar_section_link, linkable: tag2, user: user)++ visit("/latest")++ expect(sidebar).to be_visible+ expect(sidebar).to have_tags_section+ expect(sidebar).to have_tag_section_links([tag1, tag2, tag3])+ expect(sidebar).to have_tag_section_link_with_title(tag3, "tag 3 description")+ expect(sidebar).to have_tag_section_link_with_title(tag1, "tag 1 description ")+ expect(sidebar).to have_all_tags_section_link+ endend- it "should display the tags configured by the user in alphabetical order" do- Fabricate(:sidebar_section_link, linkable: tag3, user: user)- Fabricate(:sidebar_section_link, linkable: tag1, user: user)- Fabricate(:sidebar_section_link, linkable: tag2, user: user)+ describe "My messages sidebar link" do+ it "should show for user with `can_send_private_messages` permission" do+ sign_in(admin)+ visit("/")+ expect(sidebar).to have_my_messages_link+ end++ it "shouldn't show for user without `can_send_private_messages` permission" do+ SiteSetting.personal_message_enabled_groups = Group::AUTO_GROUPS[:admins]+ sign_in(user)+ visit("/")+ expect(sidebar).to have_no_my_messages_link+ end+ end+ it "shouldn't display the panel header for the main sidebar" dovisit("/latest")-expect(sidebar).to be_visible- expect(sidebar).to have_tags_section- expect(sidebar).to have_tag_section_links([tag1, tag2, tag3])- expect(sidebar).to have_tag_section_link_with_title(tag3, "tag 3 description")- expect(sidebar).to have_tag_section_link_with_title(tag1, "tag 1 description ")- expect(sidebar).to have_all_tags_section_link+ expect(sidebar).to have_no_panel_headerendend- it "shouldn't display the panel header for the main sidebar" do- visit("/latest")- expect(sidebar).to be_visible- expect(sidebar).to have_no_panel_header+ context "as anonymous user", type: :system do+ describe "My messages sidebar link" do+ it "shouldn't show for anonymous user" do+ visit("/")+ expect(sidebar).to have_no_my_messages_link+ end+ endendend