How to modify trust level for all users


(Régis Hanol) #1

Sure. Here’s what I did since they had less than 1000 users

User.where(trust_level: [0, 1]).find_each do |user|
   user.change_trust_level!(TrustLevel[2])
end

This is slow, but ensures that locked trust levels aren’t changed.

If there were more than 1000 users, I would have used this instead

User.exec_sql("UPDATE users SET trust_level = 2 WHERE trust_level IN (0, 1)")

About trust level?
Trust level changes while automatic groups do not change
Change all exsisting users to trust level 2
Missing "Invite Others..." button in PM
Migrated to Discourse and system is creating hundreds of flagged posts