mirror of
https://github.com/discourse/discourse-solved.git
synced 2025-07-12 00:13:27 +00:00
This commit makes sure to exclude the first solution when checking for an existing solution and has better tests -- the existing test does not accept the post prior to making the check.
20 lines
541 B
Ruby
20 lines
541 B
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseSolved
|
|
class FirstAcceptedPostSolutionValidator
|
|
def self.check(post, trust_level:)
|
|
return false if post.archetype != Archetype.default
|
|
return false if !post&.user&.human?
|
|
|
|
if trust_level != "any" && TrustLevel.compare(post&.user&.trust_level, trust_level.to_i)
|
|
return false
|
|
end
|
|
|
|
!DiscourseSolved::SolvedTopic
|
|
.joins(:answer_post)
|
|
.where("posts.user_id = ? AND posts.id != ?", post.user_id, post.id)
|
|
.exists?
|
|
end
|
|
end
|
|
end
|