mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Do not replace wrong avatars when renaming user
This commit is contained in:
@@ -133,14 +133,32 @@ module Jobs
|
|||||||
a["href"] = a["href"].gsub(@cooked_mention_user_path_regex, "/u/#{@new_username}") if a["href"]
|
a["href"] = a["href"].gsub(@cooked_mention_user_path_regex, "/u/#{@new_username}") if a["href"]
|
||||||
end
|
end
|
||||||
|
|
||||||
doc.css("aside.quote > div.title").each do |div|
|
doc.css("aside.quote").each do |aside|
|
||||||
|
next unless div = aside.at_css("div.title")
|
||||||
|
|
||||||
|
username_replaced = false
|
||||||
|
|
||||||
div.children.each do |child|
|
div.children.each do |child|
|
||||||
child.content = child.content.gsub(@cooked_quote_username_regex, @new_username) if child.text?
|
if child.text?
|
||||||
|
content = child.content
|
||||||
|
username_replaced = content.gsub!(@cooked_quote_username_regex, @new_username).present?
|
||||||
|
child.content = content if username_replaced
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if username_replaced || quotes_correct_user?(aside)
|
||||||
|
div.at_css("img.avatar")&.replace(@avatar_img)
|
||||||
end
|
end
|
||||||
div.at_css("img.avatar")&.replace(@avatar_img)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
doc.to_html
|
doc.to_html
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def quotes_correct_user?(aside)
|
||||||
|
Post.where(
|
||||||
|
topic_id: aside["data-topic"],
|
||||||
|
post_number: aside["data-post"]
|
||||||
|
).pluck(:user_id).first == @user_id
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -405,12 +405,18 @@ describe UsernameChanger do
|
|||||||
|
|
||||||
context 'oneboxes' do
|
context 'oneboxes' do
|
||||||
let(:quoted_post) { create_post(user: user, topic: topic, post_number: 1, raw: "quoted post") }
|
let(:quoted_post) { create_post(user: user, topic: topic, post_number: 1, raw: "quoted post") }
|
||||||
let(:avatar_url) { user.avatar_template.gsub("{size}", "40") }
|
let(:avatar_url) { user_avatar_url(user) }
|
||||||
|
let(:evil_trout) { Fabricate(:evil_trout) }
|
||||||
|
let(:another_quoted_post) { create_post(user: evil_trout, topic: topic, post_number: 2, raw: "evil post") }
|
||||||
|
|
||||||
def protocol_relative_url(url)
|
def protocol_relative_url(url)
|
||||||
url.sub(/^https?:/, '')
|
url.sub(/^https?:/, '')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def user_avatar_url(u)
|
||||||
|
u.avatar_template.gsub("{size}", "40")
|
||||||
|
end
|
||||||
|
|
||||||
it 'updates avatar for linked topics and posts' do
|
it 'updates avatar for linked topics and posts' do
|
||||||
raw = "#{quoted_post.full_url}\n#{quoted_post.topic.url}"
|
raw = "#{quoted_post.full_url}\n#{quoted_post.topic.url}"
|
||||||
post = create_post_and_change_username(raw: raw)
|
post = create_post_and_change_username(raw: raw)
|
||||||
@@ -442,6 +448,38 @@ describe UsernameChanger do
|
|||||||
</p>
|
</p>
|
||||||
HTML
|
HTML
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'does not update the wrong avatar' do
|
||||||
|
raw = "#{quoted_post.full_url}\n#{another_quoted_post.full_url}"
|
||||||
|
post = create_post_and_change_username(raw: raw)
|
||||||
|
|
||||||
|
expect(post.raw).to eq(raw)
|
||||||
|
|
||||||
|
expect(post.cooked).to match_html(<<~HTML)
|
||||||
|
<p><aside class="quote" data-post="#{quoted_post.post_number}" data-topic="#{quoted_post.topic.id}">
|
||||||
|
<div class="title">
|
||||||
|
<div class="quote-controls"></div>
|
||||||
|
<img alt="" width="20" height="20" src="#{avatar_url}" class="avatar">
|
||||||
|
<a href="#{protocol_relative_url(quoted_post.full_url)}">#{quoted_post.topic.title}</a>
|
||||||
|
</div>
|
||||||
|
<blockquote>
|
||||||
|
quoted post
|
||||||
|
</blockquote>
|
||||||
|
</aside>
|
||||||
|
<br>
|
||||||
|
<aside class="quote" data-post="#{another_quoted_post.post_number}" data-topic="#{another_quoted_post.topic.id}">
|
||||||
|
<div class="title">
|
||||||
|
<div class="quote-controls"></div>
|
||||||
|
<img alt="" width="20" height="20" src="#{user_avatar_url(evil_trout)}" class="avatar">
|
||||||
|
<a href="#{protocol_relative_url(another_quoted_post.full_url)}">#{another_quoted_post.topic.title}</a>
|
||||||
|
</div>
|
||||||
|
<blockquote>
|
||||||
|
evil post
|
||||||
|
</blockquote>
|
||||||
|
</aside>
|
||||||
|
</p>
|
||||||
|
HTML
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'updates username in small action posts' do
|
it 'updates username in small action posts' do
|
||||||
|
|||||||
Reference in New Issue
Block a user