mirror of
https://github.com/discourse/discourse-solved.git
synced 2025-07-28 15:43:26 +00:00
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".
20 lines
514 B
Ruby
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
|