diff options
author | Louis Chemineau <louis@chmn.me> | 2024-09-20 11:26:22 +0200 |
---|---|---|
committer | Louis Chemineau <louis@chmn.me> | 2024-09-23 16:59:58 +0200 |
commit | 483eaa7e726228fd957f91676295fced13c48bba (patch) | |
tree | fde2a92289f504bb8ea9e301f28fc2779c078f25 /lib | |
parent | 285136616e5df3d43c78ac0a3caa7a0e85f8d757 (diff) | |
download | nextcloud-server-backport/48207/stable28.tar.gz nextcloud-server-backport/48207/stable28.zip |
fix(users): Don't crash if disabled user is missing in the databasebackport/48207/stable28
Signed-off-by: Louis Chemineau <louis@chmn.me>
Diffstat (limited to 'lib')
-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); |