Natalie Tay 55c1eb4d60
DEV: Move solved custom fields into a table (#342)
Related: 
- https://github.com/discourse/discourse-solved/pull/309
- https://github.com/discourse/discourse-solved/pull/341

Requires:
- https://github.com/discourse/discourse/pull/31954

This commit converts all use of post and topic custom fields into a dedicated table:
- migration for copying custom field into table
- swap app usage of custom fields to table

This commit does not attempt to fix issues or optimise, and does not delete old data from custom fields _yet_.
2025-03-25 14:51:32 +08:00

28 lines
676 B
Ruby

# frozen_string_literal: true
module DiscourseSolved
module TopicAnswerMixin
def self.included(klass)
klass.attributes :has_accepted_answer, :can_have_answer
end
def has_accepted_answer
object&.solved.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
end