Please eval short Ruby script to suspend inactive users

Hmm, as I look at that I think I should be silencing an account rather than suspending. If the account is suspended, the user can’t login to claim the account.

Here is a revision …

Version 0.0.2
silence_reason = 'Inactive'
User.where("views = 0 OR approved = FALSE OR last_seen_at IS NULL")
    .where("id > 0") # avoid system users
    .find_each do |user|
  user.silence(reason: silence_reason)
  user.change_trust_level!(TrustLevel[0])
  user.save!
  logger.log_user_silence(user, silence_reason)
  DiscourseEvent.trigger(:user_silenced, user: user)
  sleep(5)
end

Yes, I will run a backup before doing any of this.
Yes, I know some existing TLs will get shuffled around and I’ll need to fix them.

In addition, to or rather than silencing, should I set Approved=false or Active=false? I believe that will force the user to click the email link rather than manually doing a login, which serves the purpose of validating the email address.

This is all related to my recent thread: notes-on-silencing-or-deleting-users

[EDIT]
I also have “purge unactivated users grace period days” set to 7.
Does a silence or suspend reset this? If so, if peeps don’t respond to an account action within 7 days, I have no problem with purging them.

Finally (yes, really) I also have “clean up inactive users after days” set to 365. I can set that down to 60 while the forum is still opening up and just let existing accounts fall off the list. Then increase it back to 365. Is that a reasonable approach for automated account pruning on a new environment?

1 Like