FIX: Respect "display name on posts" site setting (#239)
When displaying the accepted answer in the OP.
This commit is contained in:
parent
306f39c222
commit
e0cd3d11c3
|
@ -57,6 +57,7 @@ function acceptPost(post) {
|
|||
|
||||
topic.set("accepted_answer", {
|
||||
username: post.username,
|
||||
name: post.name,
|
||||
post_number: post.post_number,
|
||||
excerpt: post.cooked,
|
||||
});
|
||||
|
@ -214,16 +215,22 @@ export default {
|
|||
// keeping this here cause there is complex localization
|
||||
acceptedAnswerHtml: computed("accepted_answer", "id", function () {
|
||||
const username = this.get("accepted_answer.username");
|
||||
const name = this.get("accepted_answer.name");
|
||||
const postNumber = this.get("accepted_answer.post_number");
|
||||
|
||||
if (!username || !postNumber) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const displayedUser =
|
||||
this.siteSettings.display_name_on_posts && name
|
||||
? name
|
||||
: formatUsername(username);
|
||||
|
||||
return I18n.t("solved.accepted_html", {
|
||||
icon: iconHTML("check-square", { class: "accepted" }),
|
||||
username_lower: username.toLowerCase(),
|
||||
username: formatUsername(username),
|
||||
username: displayedUser,
|
||||
post_path: `${this.url}/${postNumber}`,
|
||||
post_number: postNumber,
|
||||
user_path: User.create({ username }).path,
|
||||
|
|
|
@ -444,7 +444,7 @@ SQL
|
|||
|
||||
def accepted_answer
|
||||
if info = accepted_answer_post_info
|
||||
{ post_number: info[0], username: info[1], excerpt: info[2] }
|
||||
{ post_number: info[0], username: info[1], excerpt: info[2], name: info[3] }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -454,7 +454,7 @@ SQL
|
|||
Post
|
||||
.where(id: accepted_answer_post_id, topic_id: object.topic.id)
|
||||
.joins(:user)
|
||||
.pluck("post_number", "username", "cooked")
|
||||
.pluck("post_number", "username", "cooked", "name")
|
||||
.first
|
||||
|
||||
if postInfo
|
||||
|
@ -463,6 +463,8 @@ SQL
|
|||
else
|
||||
nil
|
||||
end
|
||||
|
||||
postInfo[3] = SiteSetting.display_name_on_posts ? postInfo[3] : nil
|
||||
postInfo
|
||||
end
|
||||
end
|
||||
|
|
|
@ -64,6 +64,32 @@ RSpec.describe TopicsController do
|
|||
|
||||
expect(response.body).to include('"text":"This is a quoted text."')
|
||||
end
|
||||
|
||||
it "should include user name in output with the corresponding site setting" do
|
||||
SiteSetting.display_name_on_posts = true
|
||||
p2.custom_fields["is_accepted_answer"] = true
|
||||
p2.save_custom_fields
|
||||
topic.custom_fields["accepted_answer_post_id"] = p2.id
|
||||
topic.save_custom_fields
|
||||
|
||||
get "/t/#{topic.slug}/#{topic.id}.json"
|
||||
|
||||
expect(response.parsed_body["accepted_answer"]["name"]).to eq(p2.user.name)
|
||||
expect(response.parsed_body["accepted_answer"]["username"]).to eq(p2.user.username)
|
||||
end
|
||||
|
||||
it "should not include user name when site setting is disabled" do
|
||||
SiteSetting.display_name_on_posts = false
|
||||
p2.custom_fields["is_accepted_answer"] = true
|
||||
p2.save_custom_fields
|
||||
topic.custom_fields["accepted_answer_post_id"] = p2.id
|
||||
topic.save_custom_fields
|
||||
|
||||
get "/t/#{topic.slug}/#{topic.id}.json"
|
||||
|
||||
expect(response.parsed_body["accepted_answer"]["name"]).to eq(nil)
|
||||
expect(response.parsed_body["accepted_answer"]["username"]).to eq(p2.user.username)
|
||||
end
|
||||
end
|
||||
|
||||
context "with solved enabled for topics with specific tags" do
|
||||
|
|
Loading…
Reference in New Issue