Bulk Suspending Users - Suspension Reason Property


Hi All,

I am writing a Ruby script to bulk suspend users (I would like to permanently block the users from our Discourse forum, and from discussions in this thread suspension seems like the best option).

When inspecting the users in the console by doing:

me = User.find_by_username_or_email('1234@example.com')

I note that each user has the properties suspended_at and suspended_till. They are set to nil if the user is not suspended, otherwise they have a date and time. I assume that I can just create a new DateTime object with the relevant dates and times and assign to these properties to suspend the users.

However, I cannot see any properties for the suspension reason or referencing the admin who instigated the suspension. Does anyone know where I can find those properties?

It’s probably also worthwhile asking - will this procedure I have outlined work?


(Clay Heaton) #2

I have need to bulk set a suspension reason on a Discourse install that is being used for slightly non-traditional purposes. Nevertheless, I don’t see any suspended_reason field in a User db entry. Can somebody (@sam?) point me to where the suspended reason is stored in the database so that I can bulk update it for the accounts I already suspended?

(Régis Hanol) #3

It’s the last UserHistory record for that user and of type (action) “suspend_user”.