Promoting users to TL2 when joining a group - retrospectively?

I’ve modified an existing group and set the Trust level automatically granted to members when they're added value to be 2, so all members of this group will be prompted to Trust Level 2 when added to the group:

However, it doesn’t retrospectively add all the existing group members to Trust Level 2 :confused:

How can I force this to occur?

Or how can I retrospectively upgrade all the members of the group up to TL2? :thinking:


:warning: This solution is advanced. Rails command can be only done if you have SSH access to your server and should be avoided if you’re not sure of what you’re doing. In any case, always do a backup first.

Hello Richie :slight_smile:

You can use a rails script similar to this:

That should do it from the rails console:

target_group = Group.find_by_name("test")
users = User.joins(:group_users).where(group_users:{group_id:})
users.each do |u|
  u.trust_level = 2

Thanks @nathank for Delete all users not in a specific group - #2 by nathankershaw :slight_smile:


Thanks @Canapin

I’m not familiar with the rails console at all, but I ran what you posted here and it’s now sitting on END and flashing a cursor at me:

Do I need to commit this change somehow? :thinking:

(it has not promoted them to TL2)

1 Like

No, that’s just an output that doesn’t have any effect on the script execution. I believe you can press q to leave it.

You can also use this:

It may be related to the Group.find_by_name("test") part. I don’t know if it accepts the actual group name, or slug. :person_shrugging:

Also, I should have mentioned that using rails commands is fairly advanced and a backup should be made before doing this kind of stuff. I apologize for that.


Hmmm, something strange has occurred.

If I look at a user which was TL1 before I ran this rails script, I can see they are now TL2 (which is great, thank you so much!)

But, if I look at the TL2 user group, the total number of users in the group has not increased :thinking:

Similarly, if I search for one of the users that was just upgraded to TL2, they do not appear in the search results for the TL2 group:


Also, the user has not gained the TL2 badge:


1 Like

The groups are updated during a Sidekiq job.

The task is EnsureDbConsistency and can be triggered through Sidekiq, if you know how to do it. You can also wait a few hours; groups will be updated automatically. :slight_smile:

I figured it out this here:



Brilliant, thank you!

I shall wait patiently for it to resolve itself :blush:

Thanks for your time @Canapin - and your solution - you have saved me a mountain of time by doing this manually :scream:

1 Like

You’re welcome.

I was just a bit too quick suggesting a rails command without proper warning as it can go bad if we don’t really know what we’re doing. I’ll add a more visible warning to my post :slight_smile:


This rails task appears to have downgraded all our TL4 and TL3 users, to TL2 :thinking:

I’m hoping the EnsureDbConsistency task will automatically fix them all overnight :blush:

1 Like

It will, the TL3 users will be re-promoted assuming they meet the criteria still.

TL4 will need to be manually promoted.

To avoid this each user needs to be evaluated by the statement and only promoted if they’re currently below TL2.

If your TL4 users are also members of a group you could use that to promote them en-masse.


Great info, thanks @Stephen I’ll do that now :slight_smile:


Everything looks peachy this morning :blush:

Thanks again @Canapin and @Stephen :wave:


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.