Problem/Motivation
An application I maintain has certain roles that should not be expired. I have set the "Seconds of inactivity before expiring" configuration to "0", which according to this text from the README should disable the user expire functionality on this role:
> Each role can be set to a different expiration time with 0 set for roles that will not be expired.
However, users with this role were then sent the warning email.
Steps to reproduce
- Enable user_expire module
- Ensure there are some accounts that have a last access timestamp greater than 1 day ago.
- Set authenticated role "Seconds of inactivity before expiring" configuration to "0"
- Set "Warning offset time in seconds" to a small value such as 60
- Set "Send account expiration warning emails" to true.
- Save configuration form
- Run cron until user_expire_cron() is called
Warning emails will be sent to any user that has hasn't accessed the site in 60 seconds. However, they will not be blocked.
Proposed resolution
The issue is on this line when calling user_expire_find_users_to_expire_by_role() it passes in a $seconds_since_login parameter which is the timeout MINUS the offset.
So in the case of authenticated timeout = 0, and offset = 60, the value passed to this function is -60. This then breaks the assumption in the first bit of that function
if (empty($seconds_since_login)) {
return NULL;
}
The proposed fix is to add extra logic in user_expire_expire_by_role_warning() to explicitly skip a role if the timeout is set to 0, before it attempts to find accounts that would be affected.
Remaining tasks
N/A
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Issue fork user_expire-3503243
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
Comment #2
nicksanta commentedComment #5
kolin commentedI filtered out all falsy values in user_expire_get_role_rules()
These aren't used anywhere so can be safely removed.
Comment #7
trackleft2Thank you both for this report and merge request, I like the simplicity of the array_filter approach.
I've gone ahead and added some PHPUnit tests to hopefully prevent this issue from coming back once it is fixed.
Comment #8
joegraduateComment #10
joegraduateMerged. Thanks all!