diff options
author | Louis <louis@chmn.me> | 2024-09-24 10:17:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 10:17:17 +0200 |
commit | 44b54806da2737b33cdeb8eb957e73aa48da8a6b (patch) | |
tree | f9eabf6dba9cc7e6704abaf63339ef54fa8990b0 /lib/private | |
parent | eb0202c003fedbe23c75669fb742279db5a960c4 (diff) | |
parent | 483eaa7e726228fd957f91676295fced13c48bba (diff) | |
download | nextcloud-server-44b54806da2737b33cdeb8eb957e73aa48da8a6b.tar.gz nextcloud-server-44b54806da2737b33cdeb8eb957e73aa48da8a6b.zip |
Merge pull request #48283 from nextcloud/backport/48207/stable28
[stable28] fix: Don't crash if disabled user is missing in the database
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/User/LazyUser.php | 9 | ||||
-rw-r--r-- | lib/private/User/Manager.php | 19 |
2 files changed, 19 insertions, 9 deletions
diff --git a/lib/private/User/LazyUser.php b/lib/private/User/LazyUser.php index 396d3c252f1..704075c1b92 100644 --- a/lib/private/User/LazyUser.php +++ b/lib/private/User/LazyUser.php @@ -51,9 +51,12 @@ class LazyUser implements IUser { $this->user = $this->userManager->get($this->uid); } } - /** @var IUser */ - $user = $this->user; - return $user; + + if ($this->user === null) { + throw new NoUserException('User not found in backend'); + } + + return $this->user; } public function getUID() { diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index 96c77b22f76..8b92b72d792 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -56,6 +56,7 @@ use OCP\User\Backend\ISearchKnownUsersBackend; use OCP\User\Events\BeforeUserCreatedEvent; use OCP\User\Events\UserCreatedEvent; use OCP\UserInterface; +use Psr\Log\LoggerInterface; /** * Class Manager @@ -98,7 +99,8 @@ class Manager extends PublicEmitter implements IUserManager { public function __construct(IConfig $config, ICacheFactory $cacheFactory, - IEventDispatcher $eventDispatcher) { + IEventDispatcher $eventDispatcher, + private LoggerInterface $logger) { $this->config = $config; $this->cache = new WithLocalCache($cacheFactory->createDistributed('user_backend_map')); $cachedUsers = &$this->cachedUsers; @@ -353,11 +355,16 @@ class Manager extends PublicEmitter implements IUserManager { if ($search !== '') { $users = array_filter( $users, - fn (IUser $user): bool => - mb_stripos($user->getUID(), $search) !== false || - mb_stripos($user->getDisplayName(), $search) !== false || - mb_stripos($user->getEMailAddress() ?? '', $search) !== false, - ); + function (IUser $user) use ($search): bool { + try { + return mb_stripos($user->getUID(), $search) !== false || + mb_stripos($user->getDisplayName(), $search) !== false || + mb_stripos($user->getEMailAddress() ?? '', $search) !== false; + } catch (NoUserException $ex) { + $this->logger->error('Error while filtering disabled users', ['exception' => $ex, 'userUID' => $user->getUID()]); + return false; + } + }); } $tempLimit = ($limit === null ? null : $limit + $offset); |