Delete users from list

Infos:

Important:
If you are a Zammad Support or hosted customer and experience a technical issue, please refer to: support@zammad.com using your zammad-hostname / or company contract.

  • Used Zammad version: 2.5.0
  • Used Zammad installation source: ubuntu package
  • Operating system: Ubuntu 16.04
  • Browser + version: Chrome

Expected behavior:

  • Delete temp users

Actual behavior:

  • Only can make them inactive but need to delete

Steps to reproduce the behavior:

Currently this is not supported by zammad. This will come until end of the year.
Till that day, you have to do it within the database.

Please note that you can cause great data loss and damage by doing so, we do not encourage you to delete those information for now.

How do I delete users within the database? I just tried to delete two users via psql
DELETE FROM roles_users WHERE user_id = '123';
DELETE FROM users WHERE id = '123';
After Zammad restart, I can not access the webinterface and the production.log says
E, [2018-09-06T11:00:21.633953 #25729] ERROR -- : Couldn't find User with 'id'=10 (ActiveRecord::RecordNotFound)

I don’t know, I would add them back and wait for the new delete user feature.
there are 93 tables and any table that references the users table will need to be checked for rows that have the user id 123 in it and updated, and then who knows what snowball effect that will have.

Well if @MrGeneration says

Till that day, you have to do it within the database.

then I guess there is a suitable way of doing it via SQL commandline…

sure. This is how I think you could do it by hand, I’m probably wrong so I wouldn’t do it. Any row in any of the 93 tables that references user_id 123 will need to be updated or deleted, if you decide on delete then any row in any of the 93 tables that references the row you just deleted will need to be updated or deleted, and if you decide on delete, then any row in any of the 93 tables that references the row you just deleted will need to be updated or deleted, and if you decide on delete…

I guess elasticsearch will need to be reindexed too, that’s not such a big deal.

Honestly I was hoping for a nifty SQL statement from Zammad devs as they surely have done it quite some times already and of course know the db structure best :wink:

Anyway, I restored my latest snapshot to continue.

Sorry, I might not be clear enough here.
You can use the following snippet to remove a user completely.

Please not that we officially do not support it.
Use on your own risk.

users_by_email = ['some@exmaple.net', 'some@exmaple.com']
list = ''
users_by_email.each {|email|
  User.where(email: email.downcase).each {|user|
    next if user.id == 1
    next if !user.permissions?('ticket.customer')
    list += "Customer #{user.login}/#{user.email}/#{user.id} has #{Ticket.where(customer_id: user.id).count} tickets #{Ticket.where(customer_id: user.id).pluck(:number)}\n"
  }
}
puts list





users_by_email = ['some@exmaple.net', 'some@exmaple.com']
list = ''
users_by_email.each {|email|
  User.where(email: email.downcase).each {|user|
    next if user.id == 1
    next if !user.permissions?('ticket.customer')
    list += "Customer #{user.login}/#{user.email}/#{user.id} has #{Ticket.where(customer_id: user.id).count} tickets #{Ticket.where(customer_id: user.id).pluck(:number)}\n"
    Ticket.where(customer_id: user.id).each {|ticket|
      list += " Delete ticket #{ticket.number}\n"
      ticket.destroy
    }
    list += " Delete user #{user.login}/#{user.email}\n"
    user.destroy
  }
}
puts list

Edit: You need to get rid of all references, otherwise Zammad will react in unexpected ways.

1 Like

@MrGeneration Is there anywhere (github issue, email, etc) we can follow the status/progress of the user deletion feature?

We are eagerly waiting the release of this feature so we can move forward with zammad. This feature is vital/crucial as you cannot have a GDPR compliant installation of zammad without the ability to delete user data.

Edit: I found this github ticket https://github.com/zammad/zammad/issues/2074

However it is in the Icebox… what does that mean exactly?

2 Likes

I don’t know the different steps of our dev-guys. They recently changed some thing in terms of QAing.
My guess that it’s frozen (so it stays super duper fresh). Now to be honest, i think it’s simply waiting for QA. Don’t know when it will come.

@thorsteneckel might be the better reference than I am. :>

The icebox is a “SCRUM” term and means in our context that the assigned dev is currently stuck on this task and needs input/feedback/help etc. This makes it easy for us to see the current state of everything - real progress or not.

However, in this particular case it’s because we need some help with the frontend part. Our frontend resources are limited / currently working on other and higher prioritized tasks. As soon as this changes we will take the issue out of the icebox and continue working on it.

2 Likes

Also, looking forward to have delete user and all related ticket to that user in the admin settings…

I saw other system that have delete option of the user and data, if you select the delete only a soft delete means totally hide in the system but you can also back data and then there is a other option “purge” means all soft delete data will totaly delete in the system and to the database.

Does that script still work with the current version of Zammad?

yes, it’s still working. :slight_smile:

I’m using the docker-compose version of Zammad—there seems to be a conflict with the script waiting for inputs… Any ideas?

undefined method `getch' for #<IO:<STDIN>> (NoMethodError)

Sorry I’m out of the docker topic, I can’t handle that at the moment.
For productive use, we suggest to use RPM or sourcecode to use Zammad.

In my opinion rails c or maybe zammad run rails c should still work.

Found it! The gem ‘io-console’ (https://github.com/ruby/io-console) is missing within the docker image.

In case anyone wants/needs to execute the aforementioned script despite using the docker-compose version of Zammad, I’m sharing my experience:

  1. Start docker-bash: sudo docker exec -i -t <zammad_railsserver> /bin/bash
  2. Install ‘io-console’: gem install io-console
  3. Download script locally: curl https://gist.githubusercontent.com/rlue/3423aa71ca14aa5266d3436d6f2a6b65/raw/7daae8c085f1e251f4e0ad0fd03f728d410606de/purge_ticketless_customers.rb --output purge.rb
  4. Run rails console: rails c
  5. Load ‘io-console’: require 'io/console'
  6. Run local script file: load 'purge.rb'

Works like a charm! :slight_smile:

2 Likes

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