# Requesting help demoting users with invalid email addresses

**URL:** https://meta.discourse.org/t/requesting-help-demoting-users-with-invalid-email-addresses/228990
**Category:** Support
**Created:** [June 4, 2022, 3:11am UTC](https://meta.discourse.org/t/requesting-help-demoting-users-with-invalid-email-addresses/228990 "2022-06-04T03:11:50Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [June 4, 2022, 9:43am UTC](https://meta.discourse.org/t/requesting-help-demoting-users-with-invalid-email-addresses/228990/3 "2022-06-04T09:43:17Z")

</div>

Could you use the bulk admin task in this case?

> [@Administrative Bulk Operations](https://meta.discourse.org/t/administrative-bulk-operations/118349/1):
>
> ## Ensure all users are at their automatic trust level [↥](#heading--0)
> 
> * * *
> 
> Say you set the default trust level for new or invited users to a value that isn’t working out quite the way you expected (such as TL4). Now you want to change it so your users are at the trust level they would be automatically, given their current stats. The following commands will ensure all users are at the trust level they should be according to [Understanding Discourse Trust Levels | Blog](https://blog.discourse.org/2018/06/understanding-discourse-trust-levels/). **Note** : users with locked trust-levels will not be affected.
> 
> Make sure all users are set to the correct trust level:
> 
> ```plaintext
> rails c
> User.all.find_each do |user|
> Promotion.recalculate(user)
> end
> 
> ```
> 
> Refresh the group stats to reflect the changes:
> 
> `Group.ensure_consistency!`

* * *

Though I’ve just tested your second code out and it worked for me on my test user (email: test\_thirteen@here.invalid, was TL1 and is now TL0).

```plaintext
User.where(trust_level: 1).each do |u|
   if u.primary_email&.email.end_with?(".invalid")  
     u.change_trust_level!(TrustLevel[0])    
   end  
end

```

---

_[View the full topic](https://meta.discourse.org/t/requesting-help-demoting-users-with-invalid-email-addresses/228990)._
