mirror of
https://github.com/discourse/discourse-solved.git
synced 2025-02-10 05:34:55 +00:00
Ensures we remove the solution when the post marked as the solution is deleted. DEV: Added `IS_ACCEPTED_ANSWER_CUSTOM_FIELD` constant. DEV: Refactored the `PostSerializer` for better readability. PERF: Improved the `TopicViewSerializer`'s performance by looking up the `accepted_answer_post_info` from the stream first. Internal ref. dev/112251
26 lines
674 B
Ruby
26 lines
674 B
Ruby
# frozen_string_literal: true
|
|
|
|
module TopicAnswerMixin
|
|
def self.included(klass)
|
|
klass.attributes :has_accepted_answer, :can_have_answer
|
|
end
|
|
|
|
def has_accepted_answer
|
|
object.custom_fields[::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD].present?
|
|
end
|
|
|
|
def include_has_accepted_answer?
|
|
SiteSetting.solved_enabled
|
|
end
|
|
|
|
def can_have_answer
|
|
return true if SiteSetting.allow_solved_on_all_topics
|
|
return false if object.closed || object.archived
|
|
scope.allow_accepted_answers?(object.category_id, object.tags.map(&:name))
|
|
end
|
|
|
|
def include_can_have_answer?
|
|
SiteSetting.solved_enabled && SiteSetting.empty_box_on_unsolved
|
|
end
|
|
end
|