mirror of
https://github.com/discourse/discourse.git
synced 2025-03-28 17:25:44 +08:00
FIX: Extend username updates to self-mentions (#20071)
Posts with self-mentions aren't updated with username updates. This happens because mention `UserAction` entries aren't logged for self-mentions. This change updates the lookup of `Post` and `PostRevision` with mentions to bypass `UserAction` entries.
This commit is contained in:
parent
efc74cccaf
commit
2e78045af1
@ -48,8 +48,7 @@ module Jobs
|
|||||||
|
|
||||||
Post
|
Post
|
||||||
.with_deleted
|
.with_deleted
|
||||||
.joins(mentioned("posts.id"))
|
.where("raw ILIKE ?", "%@#{@old_username}%")
|
||||||
.where("a.user_id = :user_id", user_id: @user_id)
|
|
||||||
.find_each do |post|
|
.find_each do |post|
|
||||||
update_post(post)
|
update_post(post)
|
||||||
updated_post_ids << post.id
|
updated_post_ids << post.id
|
||||||
@ -64,8 +63,7 @@ module Jobs
|
|||||||
|
|
||||||
def update_revisions
|
def update_revisions
|
||||||
PostRevision
|
PostRevision
|
||||||
.joins(mentioned("post_revisions.post_id"))
|
.where("modifications SIMILAR TO ?", "%(raw|cooked)%@#{@old_username}%")
|
||||||
.where("a.user_id = :user_id", user_id: @user_id)
|
|
||||||
.find_each { |revision| update_revision(revision) }
|
.find_each { |revision| update_revision(revision) }
|
||||||
|
|
||||||
PostRevision
|
PostRevision
|
||||||
|
@ -327,6 +327,54 @@ RSpec.describe UsernameChanger do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "replaces mentions of oneself in posts" do
|
||||||
|
post = create_post_and_change_username(raw: "Hello @#{user.username}", user: user)
|
||||||
|
|
||||||
|
expect(post.raw).to eq("Hello @bar")
|
||||||
|
expect(post.cooked).to eq(%Q(<p>Hello <a class="mention" href="/u/bar">@bar</a></p>))
|
||||||
|
end
|
||||||
|
|
||||||
|
it "replaces mentions of oneself in revisions" do
|
||||||
|
revisions = [
|
||||||
|
{ raw: "Hello Foo" },
|
||||||
|
{ title: "new topic title" },
|
||||||
|
{ raw: "Hello @#{user.username}!" },
|
||||||
|
{ raw: "Hello @#{user.username}!!" },
|
||||||
|
]
|
||||||
|
|
||||||
|
post =
|
||||||
|
create_post_and_change_username(raw: "Hello @#{user.username}", revisions: revisions)
|
||||||
|
|
||||||
|
expect(post.raw).to eq("Hello @bar!!")
|
||||||
|
expect(post.cooked).to eq(%Q(<p>Hello <a class="mention" href="/u/bar">@bar</a>!!</p>))
|
||||||
|
|
||||||
|
expect(post.revisions.count).to eq(4)
|
||||||
|
|
||||||
|
expect(post.revisions[0].modifications["raw"][0]).to eq("Hello @bar")
|
||||||
|
expect(post.revisions[0].modifications["cooked"][0]).to eq(
|
||||||
|
%Q(<p>Hello <a class="mention" href="/u/bar">@bar</a></p>),
|
||||||
|
)
|
||||||
|
expect(post.revisions[0].modifications["cooked"][1]).to eq("<p>Hello Foo</p>")
|
||||||
|
|
||||||
|
expect(post.revisions[1].modifications).to include("title")
|
||||||
|
|
||||||
|
expect(post.revisions[2].modifications["raw"][0]).to eq("Hello Foo")
|
||||||
|
expect(post.revisions[2].modifications["raw"][1]).to eq("Hello @bar!")
|
||||||
|
expect(post.revisions[2].modifications["cooked"][0]).to eq("<p>Hello Foo</p>")
|
||||||
|
expect(post.revisions[2].modifications["cooked"][1]).to eq(
|
||||||
|
%Q(<p>Hello <a class="mention" href="/u/bar">@bar</a>!</p>),
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(post.revisions[3].modifications["raw"][0]).to eq("Hello @bar!")
|
||||||
|
expect(post.revisions[3].modifications["raw"][1]).to eq("Hello @bar!!")
|
||||||
|
expect(post.revisions[3].modifications["cooked"][0]).to eq(
|
||||||
|
%Q(<p>Hello <a class="mention" href="/u/bar">@bar</a>!</p>),
|
||||||
|
)
|
||||||
|
expect(post.revisions[3].modifications["cooked"][1]).to eq(
|
||||||
|
%Q(<p>Hello <a class="mention" href="/u/bar">@bar</a>!!</p>),
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
context "when using Unicode usernames" do
|
context "when using Unicode usernames" do
|
||||||
before { SiteSetting.unicode_usernames = true }
|
before { SiteSetting.unicode_usernames = true }
|
||||||
let(:user) { Fabricate(:user, username: "թռչուն") }
|
let(:user) { Fabricate(:user, username: "թռչուն") }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user