Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/private/User/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace OC\User;

use OC\Hooks\PublicEmitter;
use OC\KnownUser\KnownUserService;
use OC\Memcache\WithLocalCache;
use OCP\Config\IUserConfig;
use OCP\DB\QueryBuilder\IQueryBuilder;
Expand Down Expand Up @@ -74,8 +75,9 @@

private DisplayNameCache $displayNameCache;

// IURLGenerator can't be injected through DI
private ?IURLGenerator $urlGenerator;
// These services cannot be injected through DI because user manager is used early in install process
private ?IURLGenerator $urlGenerator = null;
private ?KnownUserService $knownUserService = null;

// This constructor can't autoload any class requiring a DB connection.
public function __construct(
Expand All @@ -91,6 +93,10 @@
$this->displayNameCache = new DisplayNameCache($cacheFactory, $this);
}

private function getKnownUserService(): KnownUserService {
return $this->knownUserService ??= Server::get(KnownUserService::class);
}

/**
* Get the active backends
* @return UserInterface[]
Expand Down Expand Up @@ -374,9 +380,14 @@
$backendUsers = $backend->searchKnownUsersByDisplayName($searcher, $pattern, $limit, $offset);
} else {
// Better than nothing, but filtering after pagination can remove lots of results.
$backendUsers = $backend->getDisplayNames($pattern, $limit, $offset);
$backendUsers = array_filter(
$backend->getDisplayNames($pattern, $limit, $offset),
fn (string $uid): bool => $this->getKnownUserService()->isKnownToUser($searcher, $uid),
ARRAY_FILTER_USE_KEY,
);

}
if (is_array($backendUsers)) {

Check failure on line 390 in lib/private/User/Manager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

RedundantCondition

lib/private/User/Manager.php:390:8: RedundantCondition: Type array<array-key, mixed> for $backendUsers is always array<array-key, mixed> (see https://psalm.dev/122)
foreach ($backendUsers as $uid => $displayName) {
$users[] = $this->getUserObject($uid, $backend);
}
Expand Down
Loading