A platform for community discussion. Free, open, simple.
FIX: Ignore suspect users that were migrated or users who were created more than six months ago (#9205)
Roman Rizzi27bc4f51c723
diff --git a/app/jobs/scheduled/enqueue_suspect_users.rb b/app/jobs/scheduled/enqueue_suspect_users.rbindex 1b94dcb3098..b88118a3a31 100644--- a/app/jobs/scheduled/enqueue_suspect_users.rb+++ b/app/jobs/scheduled/enqueue_suspect_users.rb@@ -9,15 +9,19 @@ module Jobsreturn if SiteSetting.must_approve_usersusers = User+ .distinct.activated.human_users.where(approved: false).joins(:user_profile, :user_stat)- .where("users.created_at <= ?", 1.day.ago)+ .where("users.created_at <= ? AND users.created_at >= ?", 1.day.ago, 6.months.ago).where("LENGTH(COALESCE(user_profiles.bio_raw, user_profiles.website, '')) > 0").where("user_stats.posts_read_count <= 1 AND user_stats.topics_entered <= 1").joins("LEFT OUTER JOIN reviewables r ON r.target_id = users.id AND r.target_type = 'User'").where('r.id IS NULL')+ .joins('LEFT OUTER JOIN user_custom_fields ucf ON users.id = ucf.user_id')+ .group('users.id, ucf.id')+ .having('ucf.id IS NULL OR NOT bool_or(ucf.name = ?)', 'import_id').limit(10)users.each do |user|diff --git a/spec/jobs/enqueue_suspect_users_spec.rb b/spec/jobs/enqueue_suspect_users_spec.rbindex b614899823b..b1b30e77952 100644--- a/spec/jobs/enqueue_suspect_users_spec.rb+++ b/spec/jobs/enqueue_suspect_users_spec.rb@@ -56,5 +56,29 @@ describe Jobs::EnqueueSuspectUsers doexpect(ReviewableUser.where(target: suspect_user).exists?).to eq(false)end++ it 'ignores users created more than six months ago' do+ suspect_user.update!(created_at: 1.year.ago)++ subject.execute({})++ expect(ReviewableUser.where(target: suspect_user).exists?).to eq(false)+ end++ it 'ignores users that were imported from another site' do+ suspect_user.upsert_custom_fields({ import_id: 'fake_id' })++ subject.execute({})++ expect(ReviewableUser.where(target: suspect_user).exists?).to eq(false)+ end++ it 'enqueues a suspect users with custom fields' do+ suspect_user.upsert_custom_fields({ field_a: 'value', field_b: 'value' })++ subject.execute({})++ expect(ReviewableUser.where(target: suspect_user).exists?).to eq(true)+ endendend