Skip to content

Commit 5298370

Browse files
authored
Merge pull request #63845 from nextcloud/backport/63708/stable30
[stable30] fix: Correctly filter users when the backend does not implement ISearchKnownUsersBackend
2 parents a4ba3ba + 8750675 commit 5298370

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

lib/private/User/Manager.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Doctrine\DBAL\Platforms\OraclePlatform;
1111
use OC\Hooks\PublicEmitter;
12+
use OC\KnownUser\KnownUserService;
1213
use OC\Memcache\WithLocalCache;
1314
use OCP\DB\QueryBuilder\IQueryBuilder;
1415
use OCP\EventDispatcher\IEventDispatcher;
@@ -65,6 +66,9 @@ class Manager extends PublicEmitter implements IUserManager {
6566

6667
private DisplayNameCache $displayNameCache;
6768

69+
// These services cannot be injected through DI because user manager is used early in install process
70+
private ?KnownUserService $knownUserService = null;
71+
6872
public function __construct(
6973
private IConfig $config,
7074
ICacheFactory $cacheFactory,
@@ -78,6 +82,10 @@ public function __construct(
7882
$this->displayNameCache = new DisplayNameCache($cacheFactory, $this);
7983
}
8084

85+
private function getKnownUserService(): KnownUserService {
86+
return $this->knownUserService ??= Server::get(KnownUserService::class);
87+
}
88+
8189
/**
8290
* Get the active backends
8391
* @return \OCP\UserInterface[]
@@ -375,12 +383,15 @@ public function searchKnownUsersByDisplayName(string $searcher, string $pattern,
375383
$backendUsers = $backend->searchKnownUsersByDisplayName($searcher, $pattern, $limit, $offset);
376384
} else {
377385
// Better than nothing, but filtering after pagination can remove lots of results.
378-
$backendUsers = $backend->getDisplayNames($pattern, $limit, $offset);
386+
$backendUsers = array_filter(
387+
$backend->getDisplayNames($pattern, $limit, $offset),
388+
fn (string $uid): bool => $this->getKnownUserService()->isKnownToUser($searcher, $uid),
389+
ARRAY_FILTER_USE_KEY,
390+
);
391+
379392
}
380-
if (is_array($backendUsers)) {
381-
foreach ($backendUsers as $uid => $displayName) {
382-
$users[] = $this->getUserObject($uid, $backend);
383-
}
393+
foreach ($backendUsers as $uid => $displayName) {
394+
$users[] = $this->getUserObject($uid, $backend);
384395
}
385396
}
386397

0 commit comments

Comments
 (0)