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.
This commit is contained in:
David Battersby 2023-11-13 11:06:25 +08:00 committed by GitHub
parent 1e1bb45b96
commit 4b78254065
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 1 deletions

View File

@ -646,6 +646,10 @@ class Post < ActiveRecord::Base
"#{Discourse.base_url}#{url}" "#{Discourse.base_url}#{url}"
end end
def relative_url
"#{Discourse.base_path}#{url}"
end
def url(opts = nil) def url(opts = nil)
opts ||= {} opts ||= {}

View File

@ -591,7 +591,7 @@ class PostMover
if posts.first.is_first_post? if posts.first.is_first_post?
"[#{destination_topic.title}](#{destination_topic.relative_url})" "[#{destination_topic.title}](#{destination_topic.relative_url})"
else else
"[#{destination_topic.title}](#{posts.first.url})" "[#{destination_topic.title}](#{posts.first.relative_url})"
end end
), ),
) )

View File

@ -887,6 +887,27 @@ RSpec.describe PostMover do
expect(new_post.post_revisions.size).to eq(1) expect(new_post.post_revisions.size).to eq(1)
end 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 context "with read state and other stats per user" do
def create_topic_user(user, topic, opts = {}) def create_topic_user(user, topic, opts = {})
notification_level = opts.delete(:notification_level) || :regular notification_level = opts.delete(:notification_level) || :regular

View File

@ -2135,6 +2135,17 @@ RSpec.describe Post do
end end
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 describe "public_posts_count_per_day" do
before do before do
freeze_time DateTime.parse("2017-03-01 12:00") freeze_time DateTime.parse("2017-03-01 12:00")