discourse-solved/lib/discourse_solved/first_accepted_post_solution_validator.rb
Natalie Tay 0350b46bda
FIX: Check if user has existing solution despite trust_level=any for first accepted solution validator used in automation (#377)
There exists a bug in the following trigger (see screenshot) where if the user has an existing solution already, they will still pass validation for "first accepted solution" due to the trust level being "any".
2025-06-30 15:40:16 +08:00

20 lines
514 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 = ?", post.user_id)
.exists?
end
end
end