Skip to content

A platform for community discussion. Free, open, simple.

FIX: Post moved small action links should respect subfolder installs (#24336)

David Battersby4b782540657c
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")