Skip to content

CUser::getIdByContactId() looks up the result by the wrong key #441

Closed

Description

@caseysoftware

getIdByContactId() (modules/users/users.class.php L269–273) loads users with loadAll(), which keys the list by user_id, and then reads $users[$contactId]['user_id']. It only returns the right id when the user id equals the contact id (as for the admin, which is why CUsersTest::testGetIdByContactId() passes). Otherwise it returns '' with an undefined-key warning, or another user's id.

Fix: return $users ? (string) key($users) : '' (or query user_id directly), and add a test where the two ids differ. The deprecated CUser::getUserIdByContactID() wrapper calls it too.

Blocks #458.

Fix before Phase 0 of the Identity Layer proposal (#435).

Activity

  1. added a commit that references this issue on Oct 24, 2026
    bc8eb65
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions