mirror of
https://github.com/discourse/discourse-solved.git
synced 2025-07-01 11:22:12 +00:00
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".
This commit is contained in:
parent
cee0ffc199
commit
0350b46bda
@ -5,15 +5,15 @@ module DiscourseSolved
|
|||||||
def self.check(post, trust_level:)
|
def self.check(post, trust_level:)
|
||||||
return false if post.archetype != Archetype.default
|
return false if post.archetype != Archetype.default
|
||||||
return false if !post&.user&.human?
|
return false if !post&.user&.human?
|
||||||
return true if trust_level == "any"
|
|
||||||
|
|
||||||
return false if TrustLevel.compare(post&.user&.trust_level, trust_level.to_i)
|
if trust_level != "any" && TrustLevel.compare(post&.user&.trust_level, trust_level.to_i)
|
||||||
|
return false
|
||||||
if !UserAction.where(user_id: post&.user_id, action_type: UserAction::SOLVED).exists?
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
false
|
!DiscourseSolved::SolvedTopic
|
||||||
|
.joins(:answer_post)
|
||||||
|
.where("posts.user_id = ?", post.user_id)
|
||||||
|
.exists?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "rails_helper"
|
|
||||||
|
|
||||||
describe DiscourseSolved::FirstAcceptedPostSolutionValidator do
|
describe DiscourseSolved::FirstAcceptedPostSolutionValidator do
|
||||||
fab!(:user_tl1) { Fabricate(:user, trust_level: TrustLevel[1], refresh_auto_groups: true) }
|
fab!(:user_tl1) { Fabricate(:user, trust_level: TrustLevel[1], refresh_auto_groups: true) }
|
||||||
|
|
||||||
@ -52,6 +50,13 @@ describe DiscourseSolved::FirstAcceptedPostSolutionValidator do
|
|||||||
post_1 = create_post(user: user_tl1)
|
post_1 = create_post(user: user_tl1)
|
||||||
expect(described_class.check(post_1, trust_level: "any")).to eq(true)
|
expect(described_class.check(post_1, trust_level: "any")).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "invalidates if post user already has an accepted post" do
|
||||||
|
accepted_post = create_post(user: user_tl1)
|
||||||
|
DiscourseSolved.accept_answer!(accepted_post, Discourse.system_user)
|
||||||
|
post_1 = create_post(user: user_tl1)
|
||||||
|
expect(described_class.check(post_1, trust_level: "any")).to eq(false)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when user is system" do
|
context "when user is system" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user