From 4b782540657c5df7dbd577a7fbc6bcfce82891bd Mon Sep 17 00:00:00 2001 From: David Battersby Date: Mon, 13 Nov 2023 11:06:25 +0800 Subject: [PATCH] FIX: Post moved small action links should respect subfolder installs (#24336) This change fixes an issue with small action links (when post is moved) to add the subfolder path to the url. --- app/models/post.rb | 4 ++++ app/models/post_mover.rb | 2 +- spec/models/post_mover_spec.rb | 21 +++++++++++++++++++++ spec/models/post_spec.rb | 11 +++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/app/models/post.rb b/app/models/post.rb index b8b7460d286..55521a1c3c0 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -646,6 +646,10 @@ class Post < ActiveRecord::Base "#{Discourse.base_url}#{url}" end + def relative_url + "#{Discourse.base_path}#{url}" + end + def url(opts = nil) opts ||= {} diff --git a/app/models/post_mover.rb b/app/models/post_mover.rb index 45e78acf350..40dd4696768 100644 --- a/app/models/post_mover.rb +++ b/app/models/post_mover.rb @@ -591,7 +591,7 @@ class PostMover if posts.first.is_first_post? "[#{destination_topic.title}](#{destination_topic.relative_url})" else - "[#{destination_topic.title}](#{posts.first.url})" + "[#{destination_topic.title}](#{posts.first.relative_url})" end ), ) diff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rb index 2a67ae0f279..910036a212f 100644 --- a/spec/models/post_mover_spec.rb +++ b/spec/models/post_mover_spec.rb @@ -887,6 +887,27 @@ RSpec.describe PostMover do expect(new_post.post_revisions.size).to eq(1) end + context "with subfolder installs" do + before { set_subfolder "/forum" } + + it "creates a small action with correct post url" do + moved_to = topic.move_posts(user, [p2.id], destination_topic_id: destination_topic.id) + small_action = topic.posts.last + + expect(small_action.post_type).to eq(Post.types[:small_action]) + + expected_text = + I18n.t( + "move_posts.existing_topic_moderator_post", + count: 1, + topic_link: "[#{moved_to.title}](#{p2.reload.relative_url})", + locale: :en, + ) + + expect(small_action.raw).to eq(expected_text) + end + end + context "with read state and other stats per user" do def create_topic_user(user, topic, opts = {}) notification_level = opts.delete(:notification_level) || :regular diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index b7ff4c6862e..ba13f8bf0d4 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -2135,6 +2135,17 @@ RSpec.describe Post do end end + describe "relative_url" do + it "returns the correct post url with subfolder install" do + set_subfolder "/forum" + post = Fabricate(:post) + + expect(post.relative_url).to eq( + "/forum/t/#{post.topic.slug}/#{post.topic.id}/#{post.post_number}", + ) + end + end + describe "public_posts_count_per_day" do before do freeze_time DateTime.parse("2017-03-01 12:00")