[EmailBlacklist] Only unverify exact domain matches

This commit is contained in:
Earlopain 2022-05-23 08:10:54 +02:00
parent d867ffcded
commit 3b714dd726
No known key found for this signature in database
GPG Key ID: 6CFB948E15246897
2 changed files with 8 additions and 4 deletions

View File

@ -61,7 +61,8 @@ class EmailBlacklist < ApplicationRecord
end
def unverify_accounts
matching_users = User.search(email_matches: "*@*#{domain}")
# Only unverify exact domain matches
matching_users = User.search(email_matches: "*@#{domain}")
return if matching_users.count > UNVERIFY_COUNT_TRESHOLD
matching_users.each(&:mark_unverified!)

View File

@ -37,11 +37,14 @@ class EmailBlacklistTest < ActiveSupport::TestCase
should "unverify accounts if there are few matches" do
@domain_blocked_user = create(:user, email: "0@domain.com")
@other_user = create(:user, email: "0@somethingelse.xynzs")
@other_user1 = create(:user, email: "0@prefix.domain.com")
@other_user2 = create(:user, email: "0@somethingelse.xynzs")
EmailBlacklist.create(creator: @user, domain: "domain.com", reason: "test")
@domain_blocked_user.reload
@other_user.reload
@other_user1.reload
@other_user2.reload
assert_not @domain_blocked_user.is_verified?
assert @other_user.is_verified?
assert @other_user1.is_verified?
assert @other_user2.is_verified?
end
end