Skip to content

Commit f6f2a99

Browse files
authored
Merge pull request #63844 from nextcloud/backport/63708/stable31
[stable31] fix: Correctly filter users when the backend does not implement ISearchKnownUsersBackend
2 parents ebb473f + 6a51a37 commit f6f2a99

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;
@@ -70,6 +71,9 @@ class Manager extends PublicEmitter implements IUserManager {
7071

7172
private DisplayNameCache $displayNameCache;
7273

74+
// These services cannot be injected through DI because user manager is used early in install process
75+
private ?KnownUserService $knownUserService = null;
76+
7377
public function __construct(
7478
private IConfig $config,
7579
ICacheFactory $cacheFactory,
@@ -83,6 +87,10 @@ public function __construct(
8387
$this->displayNameCache = new DisplayNameCache($cacheFactory, $this);
8488
}
8589

90+
private function getKnownUserService(): KnownUserService {
91+
return $this->knownUserService ??= Server::get(KnownUserService::class);
92+
}
93+
8694
/**
8795
* Get the active backends
8896
* @return \OCP\UserInterface[]
@@ -379,12 +387,15 @@ public function searchKnownUsersByDisplayName(string $searcher, string $pattern,
379387
$backendUsers = $backend->searchKnownUsersByDisplayName($searcher, $pattern, $limit, $offset);
380388
} else {
381389
// Better than nothing, but filtering after pagination can remove lots of results.
382-
$backendUsers = $backend->getDisplayNames($pattern, $limit, $offset);
390+
$backendUsers = array_filter(
391+
$backend->getDisplayNames($pattern, $limit, $offset),
392+
fn (string $uid): bool => $this->getKnownUserService()->isKnownToUser($searcher, $uid),
393+
ARRAY_FILTER_USE_KEY,
394+
);
395+
383396
}
384-
if (is_array($backendUsers)) {
385-
foreach ($backendUsers as $uid => $displayName) {
386-
$users[] = $this->getUserObject($uid, $backend);
387-
}
397+
foreach ($backendUsers as $uid => $displayName) {
398+
$users[] = $this->getUserObject($uid, $backend);
388399
}
389400
}
390401

0 commit comments

Comments
 (0)