# Desactivación masiva de usuarios inactivos

**URL:** https://meta.discourse.org/t/bulk-deactivation-of-inactive-users/64562
**Category:** Support
**Created:** [15 Junio, 2017 16:26 UTC](https://meta.discourse.org/t/bulk-deactivation-of-inactive-users/64562 "2017-06-15T16:26:38Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![codechef](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codechef/32/90261_2.png) [@codechef](https://meta.discourse.org/u/codechef)
#### Post date: [15 Junio, 2017 16:26 UTC](https://meta.discourse.org/t/bulk-deactivation-of-inactive-users/64562/1 "2017-06-15T16:26:39Z")

</div>

I migrated about 250 users that I’d now like to mark as inactive because they haven’t visited the forum in quite some time. Is there a way to bulk deactivate users with a ‘last seen’ date prior to some date?

My goal is to prevent emails from sending to these users. I think deactivation is the correct status because it would allow those users to re-activate if they want - correct?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [15 Junio, 2017 16:37 UTC](https://meta.discourse.org/t/bulk-deactivation-of-inactive-users/64562/2 "2017-06-15T16:37:02Z")

</div>

A simpler solution might be to adjust `suppress digest email after days`. They’d still be “active” but they’d stop getting notices.

But, if you want, it’s something like this:

```plaintext
cd /var/discourse
./launcher enter app
rails c
User.where("last_seen_at < '2016-01-01'").update_all(active: false)
exit
exit

```

---

<div class="post-metadata">

### Author: ![codechef](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codechef/32/90261_2.png) [@codechef](https://meta.discourse.org/u/codechef)
#### Post date: [15 Junio, 2017 16:45 UTC](https://meta.discourse.org/t/bulk-deactivation-of-inactive-users/64562/3 "2017-06-15T16:45:45Z")

</div>

That setting seems to only impact digest emails. Many of the categories are setup as “watch” by default, so users are getting per-post emails - not digest. Do I understand that correctly?

EDIT: I see emails going out to users that have been inactive for more than 365 days.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [15 Junio, 2017 16:49 UTC](https://meta.discourse.org/t/bulk-deactivation-of-inactive-users/64562/4 "2017-06-15T16:49:13Z")

</div>

> [@codechef](#):
>
> . Many of the categories are setup as “watch” by default, so users are getting per-post emails - not digest. Do I understand that correctly?

I think you’re right. The code I provided, though untested, should do what you want. You should backup your database before trying it.

---

<div class="post-metadata">

### Author: ![codechef](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codechef/32/90261_2.png) [@codechef](https://meta.discourse.org/u/codechef)
#### Post date: [20 Junio, 2017 17:12 UTC](https://meta.discourse.org/t/bulk-deactivation-of-inactive-users/64562/5 "2017-06-20T17:12:05Z")

</div>

Quick follow up. This script worked perfectly! I tested it in a demo environment first.

Two minor suggestions:

1. I added “and active = true” to the where criteria because I wasn’t sure if there’d be side effects to deactivating an inactive user.
2. People that come across this post is the future may want to consider adding “and id \> 0” to prevent updating the system and discobot users (though I didn’t do this myself because they were within my last\_seen\_at window.) It doesn’t appear that their last\_seen\_at is updated after the accounts are created.

---

<div class="post-metadata">

### Author: ![agemo](https://avatars.discourse-cdn.com/v4/letter/a/ac91a4/32.png) [@agemo](https://meta.discourse.org/u/agemo)
#### Post date: [4 Junio, 2024 14:10 UTC](https://meta.discourse.org/t/bulk-deactivation-of-inactive-users/64562/6 "2024-06-04T14:10:35Z")

</div>

Dado que este es un tema antiguo, ¿la desactivación masiva de usuarios inactivos es ahora una característica de Discourse o todavía necesitas ejecutar el código de @pfaffman como única solución?

---

<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: [4 Junio, 2024 14:26 UTC](https://meta.discourse.org/t/bulk-deactivation-of-inactive-users/64562/7 "2024-06-04T14:26:20Z")

</div>

Creo que ahora hay un plugin que te puede resultar útil:

> **[GitHub - discourse/discourse-auto-deactivate: This plugin will automatically deactivate stale...](https://github.com/discourse/discourse-auto-deactivate)**
>
> This plugin will automatically deactivate stale users so that they need to recomfirm their email in order to login in again

---

<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: [6 Junio, 2024 07:00 UTC](https://meta.discourse.org/t/bulk-deactivation-of-inactive-users/64562/8 "2024-06-06T07:00:31Z")

</div>

Este tema se cerró automáticamente después de 23 horas. Ya no se permiten nuevas respuestas.
