_Some_ users are unable to impersonate a pending user despite having the necessary permissions. A user with accessCp, editUsers, and impersonateUsers is able to impersonate an active user but not a pending user. Craft::$app->users->canImpersonate() does return true for the imposter.
I have reproduced this on two projects, one of which is a clean installation.
@ccchapman I think this is expected behaviour personally, a pending user ( as long as they're pending ) can't access the CP. But on the other hand maybe the canImpersonate() should indeed return false when a user is pending.
@michtio - It is confusing because an admin can impersonate a pending user and it is unclear to me why the same wouldn't work with a non-admin with the permissions described. If a non-admin user cannot impersonate a pending user, then you would expect to either receive an error or not see the impersonate link in the first place.
This is in fact a bug, and only affects the new “Copy impersonation URL” action. If you click “Login as [user]” instead, in will work as expected.
Just fixed for the next release!
@brandonkelly - This issue was using the "login as" button and not the copy impersonation URL feature. Sorry for not specifying. Let me know if you cannot reproduce it under that situation.
@ccchapman I wasn’t able to reproduce using the “Login as [user]” option. Do you have any plugins or modules that could be interfering?
@brandonkelly - No plugins or modules. I have just reproduced on a clean installation of craftcms/craft. I made a screencast which may be more helpful to see exactly what steps I am taking.
I’m able to reproduce when logged in as that second user account. Will look into it and fix.
Finally got around to this, and have fixed it for the next release.
Craft 3.6.8 is out now with the fix.