mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 03:06:53 +08:00
FIX: Ensure hashtag_lookup
falls back to system user if post user is deleted (#32466)
`hashtag_lookup` fails if called with a deleted user's ID. This change defaults to system user if the user does not exist.
This commit is contained in:
@ -111,11 +111,7 @@ module PrettyText
|
|||||||
# categories, however if the suppress_secured_categories_from_admin
|
# categories, however if the suppress_secured_categories_from_admin
|
||||||
# site setting is activated then this user will not be able to access
|
# site setting is activated then this user will not be able to access
|
||||||
# secure categories, so hashtags that are secure will not render.
|
# secure categories, so hashtags that are secure will not render.
|
||||||
if cooking_user_id.blank?
|
cooking_user = User.find_by(id: cooking_user_id) || Discourse.system_user
|
||||||
cooking_user = Discourse.system_user
|
|
||||||
else
|
|
||||||
cooking_user = User.find(cooking_user_id)
|
|
||||||
end
|
|
||||||
|
|
||||||
types_in_priority_order =
|
types_in_priority_order =
|
||||||
types_in_priority_order.select do |type|
|
types_in_priority_order.select do |type|
|
||||||
|
@ -162,5 +162,25 @@ RSpec.describe PrettyText::Helpers do
|
|||||||
Guardian.expects(:new).with(Discourse.system_user).returns(guardian_system)
|
Guardian.expects(:new).with(Discourse.system_user).returns(guardian_system)
|
||||||
PrettyText::Helpers.hashtag_lookup("somecooltag", nil, %w[category tag])
|
PrettyText::Helpers.hashtag_lookup("somecooltag", nil, %w[category tag])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "falls back to system user when cooking_user is deleted" do
|
||||||
|
user.destroy
|
||||||
|
|
||||||
|
expect(
|
||||||
|
PrettyText::Helpers.hashtag_lookup("somecooltag::tag", user.id, %w[category tag]),
|
||||||
|
).to eq(
|
||||||
|
{
|
||||||
|
relative_url: tag.url,
|
||||||
|
text: "somecooltag",
|
||||||
|
description: "Coolest things ever",
|
||||||
|
colors: nil,
|
||||||
|
icon: "tag",
|
||||||
|
id: tag.id,
|
||||||
|
slug: "somecooltag",
|
||||||
|
ref: "somecooltag::tag",
|
||||||
|
type: "tag",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user