mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-07 15:53:29 +08:00
Allows moving solved posts to new topics while retaining their solved status. Previously we just marked the original topic as "unsolved" when moving the solution post to a new or existing topic, now we carry over the solved state to the new topic if the following conditions are met: - the new topic accepts solved posts (either via SiteSetting, category setting or solved tag) - the new topic does not already have a solved post Internal ref - /t/179673
30 lines
882 B
Ruby
30 lines
882 B
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseSolved
|
|
module PostMoverExtension
|
|
private
|
|
|
|
# original_topic, post_ids, and user are attr_readers on PostMover
|
|
def move_posts_to(topic)
|
|
solved_topic = DiscourseSolved::SolvedTopic.find_by(topic_id: original_topic.id)
|
|
|
|
if solved_topic && post_ids.include?(solved_topic.answer_post_id)
|
|
accepts_answers = Guardian.new(user).allow_accepted_answers?(topic)
|
|
has_no_solution = !DiscourseSolved::SolvedTopic.exists?(topic_id: topic.id)
|
|
|
|
if accepts_answers && has_no_solution
|
|
solved_topic.update!(topic_id: topic.id)
|
|
else
|
|
DiscourseSolved::UnacceptAnswer.call(
|
|
params: {
|
|
post_id: solved_topic.answer_post_id,
|
|
},
|
|
guardian: Discourse.system_user.guardian,
|
|
)
|
|
end
|
|
end
|
|
|
|
super
|
|
end
|
|
end
|
|
end
|