There seems to be a bug.

1. set expiration to 90 days
2. activate a user
3. wait 91 days
4. user gets deactivated on cron by the module
5. reactivate the user as an admin, but the user does not log in
6. run cron again

Expected results:
The user is active and their inactivity period is reset to be 90 days from step 5.

Actual results:
The user is blocked at step 6 in the process.

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

greggles created an issue. See original summary.

greggles’s picture

Title: if a user is activated and deactivated and reactivated by an admin, reset their expiration period » if a user is activated, deactivated by the module, and reactivated by an admin, reset their expiration period
greggles’s picture

Issue summary: View changes
cafuego’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev

Bumping the version so I can make a fork.

cafuego’s picture

Status: Active » Needs review

cafuego’s picture

Also pushed a fix for the Drupal 7 version.

greggles’s picture

This change seems reasonable to me. Thanks for providing it for both d7 and d9.

It seems ideal to add a test for this if you'd be willing to do that, cafuego? I don't think we should block merging on that, though.

cafuego’s picture

Maybe? A bit of a false start but in theory now sorted.

lazysoundsystem made their first commit to this issue’s fork.

lazysoundsystem’s picture

Updated the patch as it no longer applied with yesterday's release of 8.x-1.x

berliner’s picture

StatusFileSize
new2.1 KB

Adding a static patch file version against 8.x-1.1

trackleft2 made their first commit to this issue’s fork.

trackleft2’s picture

Version: 8.x-1.x-dev » 2.x-dev
sahil.sharma@io-media.com’s picture

Hi,

By when we can expect this change mereged to 2.x and a new release or if this is an expected behaviour and not a bug so good to use patch instead.

Thanks!!

sahil.sharma@io-media.com’s picture

StatusFileSize
new1.8 KB

*

sahil.sharma@io-media.com’s picture

StatusFileSize
new2.12 KB
trackleft2’s picture

Category: Feature request » Bug report

Hi sahil.sharma@io-media.com I'll add this to the plan for the next release. Thanks! The patch looks ok to me, so feel free to use it until then.

trackleft2 changed the visibility of the branch 8.x-1.x to hidden.

trackleft2’s picture

Status: Needs review » Needs work

The PHPUnit test introduced in this MR does not appear to adequately test this functionality.

I say this because the https://git.drupalcode.org/project/user_expire/-/jobs/5542470 test passed with or without the fix. Running the "Test Only Changes" test should fail but it does not.

dhruv.mittal’s picture

Assigned: Unassigned » dhruv.mittal
dhruv.mittal’s picture

Assigned: dhruv.mittal » Unassigned
Status: Needs work » Needs review

I've added test for the changes please review

trackleft2 changed the visibility of the branch 2855005-reset-expiry-on-reactivation-7x to hidden.

trackleft2’s picture

Status: Needs review » Reviewed & tested by the community

I've tested this, and it appears to work as expected.

  • trackleft2 committed dd71e66d on 2.x authored by cafuego
    Issue #2855005 by cafuego, trackleft2, sahil.sharma@io-media.com, dhruv....
trackleft2’s picture

Status: Reviewed & tested by the community » Fixed
rafal.sereda’s picture

I don't think the proposed solution is the best one. I can imagine that updating the LastAccess value for a user can be problematic in some scenarios. This way, we completely lose information that a particular user has never logged in to our system.

trackleft2’s picture

Thank you for your comment @rafal.sereda, should we also check if the user has ever logged in before setting the value?

Possibly like this?

/**
 * Implements hook_ENTITY_TYPE_presave() for user entities.
 *
 * If the account was blocked but is now active, update the expiry so it is
 * not re-blocked by the next cron run, but only if the user has logged in before.
 */
function user_expire_user_presave(User $account) {
  $original = $account->getOriginal();
  if (
    $original &&
    $original->isBlocked() &&
    $account->isActive() &&
    $account->getLastAccessedTime() > 0
  ) {
    $account->setLastAccessTime(\Drupal::time()->getRequestTime());
  }
}

If you agree, we can open a new issue, and add it to the release plan for the next bugfix release #3536705: [Meta] Release Plan for User Expire Patch Release 2.1.2 (bugfix)

Status: Fixed » Closed (fixed)

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