Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). Varbase Media Header 9.2.1 Minor update available for module varbase_media_header (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Content Translation Redirect Module content_translation_redirect crossed 1,000 active installs.

Disable User Deletion

541 sites Security covered
View on drupal.org

This module provides control over user deletion to prevent accidental data loss or ownership issues. It allows administrators to disable options for deleting a user's content or reassigning it to the anonymous user, thereby safeguarding sensitive production data.

User deletion is always a sensitive task for two key reasons:

  • It can involve the deletion of content or changes to the content's authorization.
  • There are two open core issues: potential content regressions (Issue 3089747) or errors in the ownership of revisions (Issue 2977362).

For these reasons, it is crucial to perform this action in a highly controlled manner.

This module allows you to enable or disable the two actions associated with user deletion:

  • Delete the account and makes its content belong to the Anonymous user.
  • Delete the account and its content.

This helps prevent possible disasters in the production database.

In complex projects, the recommended process is to first test the user deletion in a staging environment. If everything works as expected, you can then proceed with the action in production.

How to configure

  • Go to "/admin/config/disable_user_deletion/settings".
  • Select the actions would you like to disable.

Disable drush commands

To apply these restrictions to Drush commands, copy this code into the file "drush/Commands/PolicyCommands.php":

/**
  * User cancel policy .
  *
  * @hook validate user:cancel
  *
  * @throws \Exception
  */
  public function usercancellValidate(CommandData $commandData) {
    // Only validate if module 'disable_user_deletion' is enabled.
    // @phpstan-ignore-next-line
    if (\Drupal::service('module_handler')->moduleExists('disable_user_deletion')) {
      // @phpstan-ignore-next-line
      $config = \Drupal::config('disable_user_deletion.settings');

      if ($config->get('user_cancel_delete') && $commandData->input()->getOption('delete-content')) {
        throw new \Exception(dt('The option to delete users has been disabled, please contact the technical administrator.'));
      }
      if ($config->get('user_cancel_reassign') && $commandData->input()->getOption('reassign-content')) {
        throw new \Exception(dt('The option to reassign content has been disabled, please contact the technical administrator.'));
      }
        }
}

Activity

Total releases
2
First release
Aug 2025
Latest release
10 months ago
Releases (12 mo)
2 ▲ from 0
Maintenance
Slowing

Releases

Version Type Release date
1.0.1 Stable Aug 18, 2025
1.x-dev Dev Aug 18, 2025