# Support deleting a user but keeping their posts

**URL:** https://meta.discourse.org/t/support-deleting-a-user-but-keeping-their-posts/14153
**Category:** Feature
**Created:** [March 26, 2014, 4:01pm UTC](https://meta.discourse.org/t/support-deleting-a-user-but-keeping-their-posts/14153 "2014-03-26T16:01:02Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Naatan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/naatan/32/108428_2.png) [@Naatan](https://meta.discourse.org/u/Naatan)
#### Post date: [March 26, 2014, 4:01pm UTC](https://meta.discourse.org/t/support-deleting-a-user-but-keeping-their-posts/14153/1 "2014-03-26T16:01:02Z")

</div>

I just had some cleanup to do following a SSO bug (that has since been resolved), I had to delete a user which had a post but it wasn’t really relevant to delete the post as well. It’d be nice if I could either delete the user and have his posts say something like “(deleted)” for the poster or be able to reassign the users posts to a different author.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [March 26, 2014, 5:13pm UTC](https://meta.discourse.org/t/support-deleting-a-user-but-keeping-their-posts/14153/2 "2014-03-26T17:13:57Z")

</div>

I think a solution for this would be to **reassign ownership of posts** to a holder user before deleting them, like `system` or one that you create - e.g. this:

![](https://global.discourse-cdn.com/meta/original/2X/1/16f6d31d545077216b0e2686669e2720591cfc8b.png)

Unfortunately, we can’t reassign ownership of posts yet.

---

<div class="post-metadata">

### Author: ![Naatan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/naatan/32/108428_2.png) [@Naatan](https://meta.discourse.org/u/Naatan)
#### Post date: [March 26, 2014, 5:17pm UTC](https://meta.discourse.org/t/support-deleting-a-user-but-keeping-their-posts/14153/3 "2014-03-26T17:17:13Z")

</div>

Yes that’d be ideal. With the option to choose which user the posts should be assigned to on a case-by-case basis (you could simply show a default user to ease this process).

---

<div class="post-metadata">

### Author: ![kpfleming](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kpfleming/32/116414_2.png) [@kpfleming](https://meta.discourse.org/u/kpfleming)
#### Post date: [March 27, 2014, 9:15am UTC](https://meta.discourse.org/t/support-deleting-a-user-but-keeping-their-posts/14153/4 "2014-03-27T09:15:19Z")

</div>

I’m curious what the value of deleting the user account is versus just disabling it so it cannot be used.

---

<div class="post-metadata">

### Author: ![Naatan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/naatan/32/108428_2.png) [@Naatan](https://meta.discourse.org/u/Naatan)
#### Post date: [March 27, 2014, 2:49pm UTC](https://meta.discourse.org/t/support-deleting-a-user-but-keeping-their-posts/14153/5 "2014-03-27T14:49:50Z")

</div>

Deleting it clears up their username, email and SSO account(s) to be used again. In my particular use-case this was necessary as the user signed up twice with similar data causing a bug to be triggered in Discourse (which has since been resolved). The point is though that I’d want to be able to troubleshoot the issue myself rather than having to fully rely on the Discourse devs to fix it (and in this case, the fix they provided only fixed things going forward, it didnt retroactively fix the issues the bug had caused).

In an ideal setting where everything goes 100% perfectly you likely wouldn’t ever need to use this functionality, but who among us has ever been in such a situation?

---

<div class="post-metadata">

### Author: ![lightyear](https://avatars.discourse-cdn.com/v4/letter/l/848f3c/32.png) [@lightyear](https://meta.discourse.org/u/lightyear)
#### Post date: [March 27, 2014, 3:46pm UTC](https://meta.discourse.org/t/support-deleting-a-user-but-keeping-their-posts/14153/6 "2014-03-27T15:46:45Z")

</div>

> [@Naatan](#):
>
> In my particular use-case this was necessary as the user signed up twice with similar data causing a bug to be triggered in Discourse (which has since been resolved).

This sounds like a real edge case to me. I’d personally prefer the way that “disabling” vs. “deleting” is supposed to work. And as you say yourself:

> [@Naatan](#):
>
> In an ideal setting where everything goes 100% perfectly you likely wouldn’t ever need to use this functionality

Therefore I’d be against adding it. There is simply no way to anticipate everything that goes wrong and have a feature for every edge in this. It is more work to do that than fix manually the few times it happens. I’ll just quote [xkcd](http://xkcd.com/1205/) on that:

![](https://global.discourse-cdn.com/meta/original/3X/7/c/7c53f8975b588598c45df274586af24e6b9482b9.png)

That said, I’m happy to help you out. Here is a little script that you can copy paste into the rails console (start with `bundle exec rails c` from within your discourse install directory) to re-assign all posts of the soon-to-be-deleted-user to the new\_user:

```ruby
USERNAME_TO_BE_DELETED = "jessamyn"
NEW_USERNAME = "clay_7"
new_user = User.find_by_username(NEW_USERNAME)
old_user = User.find_by_username(USERNAME_TO_BE_DELETED)
posts = old_user.posts
topics = old_user.topics

posts.each do |post|
  post.user = new_user
  post.save()
end

topics.each do |topic|
  topic.user = new_user
  topic.save()
end

```

And you are safe to delete the old user. Be aware, some caches will still show the old data. Also: never copy-paste code into a production systems console that you’ve found on a forum 😉 – Code comes without any warranty.

---

<div class="post-metadata">

### Author: ![Naatan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/naatan/32/108428_2.png) [@Naatan](https://meta.discourse.org/u/Naatan)
#### Post date: [March 27, 2014, 7:03pm UTC](https://meta.discourse.org/t/support-deleting-a-user-but-keeping-their-posts/14153/7 "2014-03-27T19:03:08Z")

</div>

> [@lightyear](#):
>
> There is simply no way to anticipate everything that goes wrong and have a feature for every edge in this.

This is exactly _why_ this feature is needed. It allows you to address unforeseeable edge cases, whereas disable user does not.

Thanks for the script, I’ll bookmark is but have no need for it at this point in time. I’m simply requesting the feature because it’s inevitable that others will walk into a similar issue sooner or later.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [March 27, 2014, 11:47pm UTC](https://meta.discourse.org/t/support-deleting-a-user-but-keeping-their-posts/14153/8 "2014-03-27T23:47:12Z")

</div>

As @riking, the feature we want is re-assign ownership, it paves the way here.

---

<div class="post-metadata">

### Author: ![lightyear](https://avatars.discourse-cdn.com/v4/letter/l/848f3c/32.png) [@lightyear](https://meta.discourse.org/u/lightyear)
#### Post date: [March 28, 2014, 10:58am UTC](https://meta.discourse.org/t/support-deleting-a-user-but-keeping-their-posts/14153/9 "2014-03-28T10:58:36Z")

</div>

Would that be one of [the aforementioned “admin menu per post”](https://meta.discourse.org/t/wiki-topic-mini-spec/13966/9) features?

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [March 28, 2014, 3:22pm UTC](https://meta.discourse.org/t/support-deleting-a-user-but-keeping-their-posts/14153/10 "2014-03-28T15:22:16Z")

</div>

I’ve gotten some of the way in here:

[https://meta.discourse.org/t/wip-changing-ownership-of-posts/14217](https://meta.discourse.org/t/wip-changing-ownership-of-posts/14217)

---

<div class="post-metadata">

### Author: ![lightyear](https://avatars.discourse-cdn.com/v4/letter/l/848f3c/32.png) [@lightyear](https://meta.discourse.org/u/lightyear)
#### Post date: [March 28, 2014, 3:38pm UTC](https://meta.discourse.org/t/support-deleting-a-user-but-keeping-their-posts/14153/11 "2014-03-28T15:38:28Z")

</div>

> [@riking](#):
>
> I’ve gotten some of the way in here

Looks like I can’t comment on changesets before they are in a PR, will wait until then to help with the review.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [March 25, 2015, 5:07am UTC](https://meta.discourse.org/t/support-deleting-a-user-but-keeping-their-posts/14153/12 "2015-03-25T05:07:24Z")

</div>

@neil also built the anonymize user function which works well for this, plus we have reassign post ownership so I consider this complete.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [March 25, 2015, 5:07am UTC](https://meta.discourse.org/t/support-deleting-a-user-but-keeping-their-posts/14153/13 "2015-03-25T05:07:29Z")

</div>


