discourse-solved/lib/discourse_solved/first_accepted_post_solution_validator.rb
Natalie Tay 041b58eed1
FIX: Exclude the first post itself when checking if an existing solution from the user exists (#378)
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.
2025-07-02 11:45:14 +08:00

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