Email Blacklist - Bulk Delete/Disable Question

AI-generated summary

The discussion revolves around bulk management of user accounts based on their registration email domain, particularly for handling spam accounts using a blacklisted domain. markersocial seeks a way to delete, suspend, or anonymize users registered with a specific domain, noting that the accounts are not migrated and the volume is large. codinghorror warns of potential performance issues, while pfaffman confirms it’s possible via the Rails console. fzngagan provides a detailed method to identify users by email domain and anonymize them using the UserAnonymizer class, offering sample code to filter users by domain and anonymize them. markersocial appreciates the solution and asks about bulk silencing, to which fzngagan confirms it’s possible through the Rails console.

After the domains are blacklisted, the accounts that have already made it through are unaffected and can still be used.

I want to ask if anyone knows of a way to bulk destroy (delete user + all of their content), suspend or silence users based on their registration email domain?

In my case this would allow deleting/disabling hundreds of thousands of accounts that used the catchall domain technique to register.

Was this migrated data? Deleting that many accounts is going to be very, very painful – unless they all have almost no content.

You can do it from the rails console, but it does sound like it could be very messy.

@codinghorror - It’s not migrated data. I don’t mind painful and slow as the alternative of allowing the accounts to stay is probably worse :hot_face: For amounts of content, it’s a mix, some have none (usually the spammers intend to use these accounts later), some have minimal, some have heaps.

@pfaffman Great! Do you know how? Haha :pray:

Have you given a thought to anonymizing the users?

@fzngagan That might be a solid solution. Know if there a way to do this in bulk?

Yes. It can be done from the rails console. But the question is, on what criteria do you want to anonymize them?

@fzngagan Great! The criteria would be, all emails that use a specific domain in their registration email. E.g. example@blacklisted.com, example2@blacklisted.com

In rails console, type these commands and see if they give expected results(replace you email id pattern with ‘@gmail.com’)

idlist = UserEmail.where("email like '%@gmail.com'").pluck(:user_id)
users = User.find(idlist)

then (proceed with caution)

system_user = Discourse.system_user
users.each do |user|
  UserAnonymizer.new(user, system_user).make_anonymous
end

I’m not an expert in performance related stuff, so I don’t know exactly what would happen if number of users is big.

@fzngagan Wow nice, thanks heaps! :slight_smile: I really appreciate it.

I’ll make sure everything is recently backed up before giving this a shot.

Quick question, do you know if bulk silencing the users (forever) using this technique is possible?

Yes. Rails console can do mostly everything that can be done from code.