FIX: Don't enqueue imported users when there're multiple custom fields. (#11559)

My initial implementation didn't consider this case. We should skip imported users if the "imported_id" field is present, even if there're other custom fields.
This commit is contained in:
Roman Rizzi 2020-12-22 14:28:07 -03:00 committed by GitHub
parent a4fb28ccd8
commit 8a7fe3b276
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View File

@ -19,9 +19,16 @@ module Jobs
.where("user_stats.posts_read_count <= 1 AND user_stats.topics_entered <= 1") .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'") .joins("LEFT OUTER JOIN reviewables r ON r.target_id = users.id AND r.target_type = 'User'")
.where('r.id IS NULL') .where('r.id IS NULL')
.joins('LEFT OUTER JOIN user_custom_fields ucf ON users.id = ucf.user_id') .joins(
.group('users.id, ucf.id') <<~SQL
.having('ucf.id IS NULL OR NOT bool_or(ucf.name = ?)', 'import_id') LEFT OUTER JOIN (
SELECT user_id
FROM user_custom_fields
WHERE user_custom_fields.name = 'import_id'
) AS ucf ON ucf.user_id = users.id
SQL
)
.where('ucf.user_id IS NULL')
.limit(10) .limit(10)
users.each do |user| users.each do |user|

View File

@ -80,5 +80,13 @@ describe Jobs::EnqueueSuspectUsers do
expect(ReviewableUser.where(target: suspect_user).exists?).to eq(true) expect(ReviewableUser.where(target: suspect_user).exists?).to eq(true)
end end
it 'ignores imported users even if they have multiple custom fields' do
suspect_user.upsert_custom_fields({ field_a: 'value', field_b: 'value', import_id: 'fake_id' })
subject.execute({})
expect(ReviewableUser.where(target: suspect_user).exists?).to eq(false)
end
end end
end end