…ve email when user foo(email@example.com) is merged into user bar(without email), if user send an email(from firstname.lastname@example.org) to RT, we want RT to load user bar instead. But because RT::User::LoadByEmail calls RT::User::CanonicalizeEmailAddress, in previous version it actually loads first user that doesn't have email, which is wrong.
If a user record has other users merged into it and they are not unmerged before shredding, the merged users are left in a state where they can't be loaded because they still point to another user (EffectiveId), but that id is no longer in the DB.
When a user with another user merged into it is shredded, the attributes on that user are also shredded, but the merged user will remain, along with attributes that may point to the now missing user id. This script cleans up attributes if the merged-into user record is now gone.
When running shredder to clean up users, the effective id for a merged ticket can be shredded. Add error checking when loading an effective id to detect this case. On failure, return the id of the current user id and warn that the user it was merged into is missing.
Disabling a user did not disable all of the users merged into them. This caused users disabled users to apparently still appear via the web UI in user searches, as their merged-in (non-disabled) users often still matched the search. Explicitly propagate Disabled updates on users down into their merged-in equivalents. Note that changes to sub-users do not propagate upward; loading them takes explicit effort, changing them could be more surpising action-at-a-distance, and introduces difficulties with dealing with cycles.
0357340 switched several uses of $RT::SystemUser to $self->CurrentUser, on the basis that the current user should be propagated throughout, rather than fixed to the current user. However, the change in CanonicalizeEmailAddress was overzealous, as that can be called as a class method. As the $canonical_user in this context is lexical, is not altered, and should not be ACL'd in any way, hardcoding the system user is correct; restore it.