From f44ec18fd23960a22a5d5d397959430d6b84cb1c Mon Sep 17 00:00:00 2001 From: David Battersby Date: Tue, 9 Jul 2024 12:42:38 +0400 Subject: [PATCH] DEV: update base url links to respect subfolder installs (#27740) This change eliminates a couple of instances where subfolder urls are badly formatted, in most cases we can use Discourse.base_url_no_prefix to prevent adding the subfolder to the base url. --- app/helpers/email_helper.rb | 2 +- app/views/email/_mailing_list_post.html.erb | 2 +- lib/email/sender.rb | 4 +++- spec/helpers/email_helper_spec.rb | 11 +++++++++++ spec/models/post_spec.rb | 11 +++++++++++ 5 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 spec/helpers/email_helper_spec.rb diff --git a/app/helpers/email_helper.rb b/app/helpers/email_helper.rb index 64cb028c535..a542c3b66d3 100644 --- a/app/helpers/email_helper.rb +++ b/app/helpers/email_helper.rb @@ -24,7 +24,7 @@ module EmailHelper def email_topic_link(topic) url, title = extract_details(topic) - raw "#{title}" + raw "#{title}" end def email_html_template diff --git a/app/views/email/_mailing_list_post.html.erb b/app/views/email/_mailing_list_post.html.erb index 43d09820e2e..a16e0d525af 100644 --- a/app/views/email/_mailing_list_post.html.erb +++ b/app/views/email/_mailing_list_post.html.erb @@ -1,5 +1,5 @@
  • - <%= raw format_topic_title(topic.title) %> + <%= raw format_topic_title(topic.title) %> <%= post_count %> <%= category_badge(topic.category, inline_style: true, absolute_url: true) %>
  • diff --git a/lib/email/sender.rb b/lib/email/sender.rb index 5ec4acd8dac..59286747a5f 100644 --- a/lib/email/sender.rb +++ b/lib/email/sender.rb @@ -171,7 +171,9 @@ module Email if topic if SiteSetting.private_email? - @message.header["List-Archive"] = "#{Discourse.base_url}#{topic.slugless_url}" + @message.header[ + "List-Archive" + ] = "#{Discourse.base_url_no_prefix}#{topic.slugless_url}" else @message.header["List-Archive"] = topic.url end diff --git a/spec/helpers/email_helper_spec.rb b/spec/helpers/email_helper_spec.rb new file mode 100644 index 00000000000..5b4b318cc05 --- /dev/null +++ b/spec/helpers/email_helper_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +RSpec.describe EmailHelper do + describe "#email_topic_link" do + it "respects subfolder" do + set_subfolder "/forum" + topic = Fabricate(:topic) + expect(helper.email_topic_link(topic)).to include("#{Discourse.base_url_no_prefix}/forum/t") + end + end +end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 2ca17c1e4ec..1f78830c302 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -2238,6 +2238,17 @@ RSpec.describe Post do end end + describe "full_url" do + it "returns the correct post url with subfolder install" do + set_subfolder "/forum" + post = Fabricate(:post) + + expect(post.full_url).to eq( + "#{Discourse.base_url_no_prefix}/forum/t/#{post.topic.slug}/#{post.topic.id}/#{post.post_number}", + ) + end + end + describe "public_posts_count_per_day" do before do freeze_time_safe