mirror of
https://github.com/discourse/discourse.git
synced 2026-08-11 02:59:07 +08:00
This adds defense-in-depth for the unlikely edge case where an admin converts an accepted answer to a whisper. Previously, it would be serialized to all clients, just like any accepted answer. After this fix, it'll be omitted. Co-authored-by: discourse-patch-triage <272280883+discourse-patch-triage[bot]@users.noreply.github.com>
34 lines
859 B
Ruby
Vendored
34 lines
859 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module DiscourseSolved
|
|
module AcceptedAnswersHelper
|
|
def self.serialize(topic, guardian)
|
|
return nil unless topic.topic_answers&.any?
|
|
|
|
ActiveRecord::Associations::Preloader.new(
|
|
records: [topic.solved],
|
|
associations: {
|
|
topic_answers: [{ post: :user }, :accepter],
|
|
},
|
|
).call
|
|
|
|
answers =
|
|
topic
|
|
.topic_answers
|
|
.select do |topic_answer|
|
|
topic_answer.post.present? && guardian.can_see_post?(topic_answer.post)
|
|
end
|
|
.sort_by { |ta| ta.post.created_at }
|
|
.map do |ta|
|
|
AcceptedAnswerSerializer.new(
|
|
ta.post,
|
|
scope: guardian,
|
|
root: false,
|
|
accepter: ta.accepter,
|
|
).as_json
|
|
end
|
|
|
|
answers.presence
|
|
end
|
|
end
|
|
end
|