Delete user from discourse-docker using ssh

Hello,

How do you remove user by using

./launcher enter app

and deleting the user by rake?
Just like you create admin with

rake admin:create

Is there a way to delete user like that?

Thanks,
NInetailz

As you said, you can enter the container with

./launcher enter app

Then, you will need to launch the rails console with

rails c

Once you’re in the rails console, you can delete a user with

User.find_by(username: "foobar").destroy
6 Likes

So i did that and it did removed the user but it showed this (END) line when i kept pressing enter and i closed it by ctrl+z. Is that the right way to close rails c? something telling me its not …

root@xxx:~# cd /var/xxx/
root@xxx:/var/xxx# ./launcher enter app
root@xxx-app:/# rails c
[1] pry(main)> User.find_by(username: “anon61470549”).destroy
=> #<User:0x007fc7283af178
id: -2,
username: “anon61470549”,
created_at: Thu, 07 Jan 2016 01:46:38 UTC +00:00,
updated_at: Tue, 12 Jan 2016 03:00:37 UTC +00:00,
name: nil,
seen_notification_id: 0,
last_posted_at: nil,
email: “anon61470549@example.com”,
password_hash:
“xxx”,
salt: “xx”,
active: false,
username_lower: “anon61470549”,
auth_token: nil,
last_seen_at: nil,
admin: false,
last_emailed_at: nil,
email_digests: false,
trust_level: 0,
email_private_messages: false,
email_direct: false,
approved: false,
approved_by_id: nil,
approved_at: nil,
digest_after_days: 7,
previous_visit_at: nil,
suspended_at: nil,
suspended_till: nil,
date_of_birth: nil,
auto_track_topics_after_msecs: 240000,
views: 0,
flag_level: 0,
ip_address: nil,
new_topic_duration_minutes: 2880,
external_links_in_new_tab: false,
enable_quoting: true,
moderator: false,
blocked: false,
dynamic_favicon: false,
title: nil,
uploaded_avatar_id: nil,
email_always: false,
mailing_list_mode: false,
locale: nil,
primary_group_id: nil,
registration_ip_address: nil,
last_redirected_to_top_at: nil,
disable_jump_reply: false,
edit_history_public: true,
trust_level_locked: false,
staged: false,
automatically_unpin_topics: true>

[1]+ Stopped rails c

No that is not the correct way… type:

exit enter

twice.

2 Likes

Hi,

I’ve tried the way @zogstrip told. The user is no more on the discourse yet I got internal server error when trying to open all of the topics that the user posted in.

The following lines are from production.log and it is the only log that I could fetch so far. What is going wrong?

Started GET "/t/bilginin-tamamina-sahip-olmadiginizda-fikir-sahibi-olmadan-once-yapmaniz-gereken-3-sey/10594" for 80.5.152.180 at 2016-01-12 21:36:57 +0000
Processing by TopicsController#show as HTML
  Parameters: {"slug"=>"bilginin-tamamina-sahip-olmadiginizda-fikir-sahibi-olmadan-once-yapmaniz-gereken-3-sey", "topic_id"=>"10594"}
Completed 500 Internal Server Error in 170ms (ActiveRecord: 23.8ms)
NoMethodError (undefined method ``id`` for nil:NilClass)
/var/www/discourse/app/serializers/topic_post_count_serializer.rb:6:in ``id'

UPDATE:
The user’s posts are still on the posts table and the error is most likely because of that the user data
of the post could not be found. Well, deleting posts of the user is just a simple query and I guess it is going to solve this but sanitizing all the data (post, like counts etc.) would take some time to achieve. Is there any sort of script to delete (or anonymize) all post data associated with a specific user (or user_id)?

What would the syntax be to do this by user id?

User.find_by(id: "foobar").destroy
User.find_by(id: 1234).destroy
2 Likes

This topic was automatically closed after 3069 days. New replies are no longer allowed.