FIX: Prevent low score flags from auto-closing a topic if the reviewable default visibility is higher than low (#9375)

This commit is contained in:
Roman Rizzi 2020-04-08 10:44:31 -03:00 committed by GitHub
parent 874999941a
commit 8e1bdc9458
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 2 deletions

View File

@ -1423,8 +1423,9 @@ class Topic < ActiveRecord::Base
scores = ReviewableScore.pending scores = ReviewableScore.pending
.joins(:reviewable) .joins(:reviewable)
.where("reviewables.topic_id = ?", self.id) .where('reviewable_scores.score >= ?', Reviewable.min_score_for_priority)
.pluck("COUNT(DISTINCT reviewable_scores.user_id), COALESCE(SUM(reviewable_scores.score), 0.0)") .where('reviewables.topic_id = ?', self.id)
.pluck('COUNT(DISTINCT reviewable_scores.user_id), COALESCE(SUM(reviewable_scores.score), 0.0)')
.first .first
scores[0] >= SiteSetting.num_flaggers_to_close_topic && scores[1] >= Reviewable.score_to_auto_close_topic scores[0] >= SiteSetting.num_flaggers_to_close_topic && scores[1] >= Reviewable.score_to_auto_close_topic

View File

@ -2574,4 +2574,40 @@ describe Topic do
expect(user.user_profile.reload.featured_topic).to eq(nil) expect(user.user_profile.reload.featured_topic).to eq(nil)
end end
end end
describe '#auto_close_threshold_reached?' do
before do
Reviewable.set_priorities(low: 2.0, medium: 6.0, high: 9.0)
SiteSetting.num_flaggers_to_close_topic = 2
SiteSetting.reviewable_default_visibility = 'medium'
SiteSetting.auto_close_topic_sensitivity = Reviewable.sensitivity[:high]
post = Fabricate(:post)
@topic = post.topic
@reviewable = Fabricate(:reviewable_flagged_post, target: post, topic: @topic)
end
it 'ignores flags with a low score' do
5.times do
@reviewable.add_score(
Fabricate(:user, trust_level: TrustLevel[0]),
PostActionType.types[:spam],
created_at: 1.minute.ago
)
end
expect(@topic.auto_close_threshold_reached?).to eq(false)
end
it 'returns true when the flags have a high score' do
5.times do
@reviewable.add_score(
Fabricate(:user, admin: true),
PostActionType.types[:spam],
created_at: 1.minute.ago
)
end
expect(@topic.auto_close_threshold_reached?).to eq(true)
end
end
end end