From da5c7c9694c8404846dc322e4802a1c4b55c7ed9 Mon Sep 17 00:00:00 2001 From: Git'Fellow <12234510+solracsf@users.noreply.github.com> Date: Thu, 6 Aug 2026 19:32:30 +0100 Subject: [PATCH] fix(backend): Keep the display name ordering when searching guests orderBy() replaces the order-by clause instead of appending to it, so the second call dropped the display name ordering and left the results sorted by user id only. With hashed user ids that ordering is effectively random, and it also decides which guests a limited search returns. Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> --- lib/UserBackend.php | 2 +- tests/unit/UserBackendTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/UserBackend.php b/lib/UserBackend.php index f89758141..de3bb415f 100644 --- a/lib/UserBackend.php +++ b/lib/UserBackend.php @@ -233,7 +233,7 @@ public function getDisplayNames($search = '', $limit = null, $offset = null): ar ->orWhere($query->expr()->iLike('displayname', $query->createPositionalParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%'))) ->orWhere($query->expr()->iLike('configvalue', $query->createPositionalParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%'))) ->orderBy($query->func()->lower('displayname'), 'ASC') - ->orderBy('uid_lower', 'ASC') + ->addOrderBy('uid_lower', 'ASC') ->setMaxResults($limit) ->setFirstResult($offset); } diff --git a/tests/unit/UserBackendTest.php b/tests/unit/UserBackendTest.php index 4cdaa5400..c27b94cb3 100644 --- a/tests/unit/UserBackendTest.php +++ b/tests/unit/UserBackendTest.php @@ -126,4 +126,17 @@ public function testOutdatedPasswordHashIsUpgradedOnEmailLogin(): void { $this->assertNotEquals($legacyHash, $this->backend->getPasswordHash($uid)); } + + /** + * Searching orders by display name first, which also decides which + * guests a limited search returns. + */ + public function testSearchIsOrderedByDisplayName(): void { + $this->backend->createUser('aaa@example.tld', 'bar'); + $this->backend->setDisplayName('aaa@example.tld', 'Zoe'); + $this->backend->createUser('zzz@example.tld', 'bar'); + $this->backend->setDisplayName('zzz@example.tld', 'Alice'); + + $this->assertEquals(['Alice', 'Zoe'], array_values($this->backend->getDisplayNames('example.tld'))); + } }