Problem/Motivation

When the "Notification User Before Deletion" option is enabled, I expect all users to be notified before being deleted.
However, this is not happening. Users who have already exceeded the configured threshold (e.g., inactivity period)
are being deleted immediately without receiving any prior notification.
This defeats the purpose of the functionality, which is to give users a chance to take action after being notified.

This issue is especially problematic on live/production sites, where users may already exceed the inactivity threshold
at the time the feature is enabled, resulting in their immediate deletion without a chance to respond.

Steps to reproduce

  1. Enable the "Notification User Before Deletion" setting.
  2. Set a low threshold for inactivity before deletion.
  3. Ensure there are users who have already exceeded this threshold when cron runs.
  4. Run cron.
  5. Observe that users are deleted without being notified.

Proposed resolution

Add an extra validation step using the purge_users_notifications table.

Check if the user has already been notified and if the notification date has passed the configured waiting period.

Only allow the user to be deleted after this condition is met.

Remaining tasks

  • Add the new validation to the purge logic.
  • Ensure only users who were notified and have passed the notification wait time are deleted.
  • Write automated tests to cover this behavior.
  • Update documentation if needed.

User interface changes

No changes to the user interface are required.

API changes

No API changes are required.

Data model changes

No data model changes are needed, assuming the purge_users_notifications table is already used to store notifications.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

saidatom created an issue. See original summary.

saidatom’s picture

Version: 4.0.0-rc2 » 4.x-dev
mably’s picture

I think that it could easily be done using the new policy mechanism.

We could simply create a new "Notification required before purge" policy.

Will see what I can do.

saidatom’s picture

@mably we have send_email_user_before_notification that is the variable we need, why add one more option?

mably’s picture

Has been implemented as a new condition in the following issue #3427680: Use plugins and condition to create advanced policies.

mably’s picture

@saidatom could you give a try to the new 5.0.0-alpha1 version with the "Notification required" condition and tell me if it solves your problem?

Notification required condition

mably’s picture

saidatom’s picture

@mably for me not working and the module in version 5 has a lot of duplicated configuration. I think we should have policy rules and remove the old form config.

mably’s picture

@saidatom could you describe in detail what is not working exactly?

I do not plan to remove the existing configuration for now.

Seems a bit risky to me and both can be used simultaneously without any problem.

The old config allows to combine connection status rules with OR logic.
On the other hand, the policy conditions use AND logic.

claudiu.cristea made their first commit to this issue’s fork.

claudiu.cristea’s picture

Version: 4.x-dev » 5.x-dev
claudiu.cristea’s picture

Issue tags: +Needs tests

I guess we need a test to prove the bug

mably’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

One edge case to consider with the notification-before-purge mechanism (both checkNotification() in the global config path and NotificationRequiredCondition in the policy path): users without a valid email address.

If the notification email fails to send (invalid or empty email), no record is written to purge_users_notifications. Then neither checkNotification() nor the NotificationRequiredCondition will ever allow those users to be purged. They would be permanently stuck — matching purge criteria but never purgeable.

Possible approaches:

1. Filter out users with empty or invalid emails from the notification candidates entirely and purge them directly — they cannot be notified, so requiring notification is pointless.
2. Insert the notification record regardless of email delivery success (treat "attempted to notify" as sufficient).
3. Log the failure prominently so administrators can manually delete the account. The module already logs a message, but it could be surfaced more visibly (e.g. via a watchdog warning or a status report entry).

mably’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.