diff --git a/app/init/resources.php b/app/init/resources.php index 3993ec2507..3481e73e0b 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -390,16 +390,19 @@ Http::setResource('user', function (string $mode, Document $project, Document $c $user = null; if ($mode === APP_MODE_ADMIN) { - $user = new User($dbForPlatform->getDocument('users', $store->getProperty('id', ''))->getArrayCopy()); + /** @var User $user */ + $user = $dbForPlatform->getDocument('users', $store->getProperty('id', '')); } else { if ($project->isEmpty()) { $user = new User([]); } else { if (! empty($store->getProperty('id', ''))) { if ($project->getId() === 'console') { - $user = new User($dbForPlatform->getDocument('users', $store->getProperty('id', ''))->getArrayCopy()); + /** @var User $user */ + $user = $dbForPlatform->getDocument('users', $store->getProperty('id', '')); } else { - $user = new User($dbForProject->getDocument('users', $store->getProperty('id', ''))->getArrayCopy()); + /** @var User $user */ + $user = $dbForProject->getDocument('users', $store->getProperty('id', '')); } } } @@ -429,9 +432,11 @@ Http::setResource('user', function (string $mode, Document $project, Document $c $jwtUserId = $payload['userId'] ?? ''; if (! empty($jwtUserId)) { if ($mode === APP_MODE_ADMIN) { - $user = new User($dbForPlatform->getDocument('users', $jwtUserId)->getArrayCopy()); + /** @var User $user */ + $user = $dbForPlatform->getDocument('users', $jwtUserId); } else { - $user = new User($dbForProject->getDocument('users', $jwtUserId)->getArrayCopy()); + /** @var User $user */ + $user = $dbForProject->getDocument('users', $jwtUserId); } } $jwtSessionId = $payload['sessionId'] ?? ''; @@ -450,9 +455,9 @@ Http::setResource('user', function (string $mode, Document $project, Document $c throw new Exception(Exception::USER_API_KEY_AND_SESSION_SET); } - $accountKeyDoc = $dbForPlatform->getAuthorization()->skip(fn () => $dbForPlatform->getDocument('users', $accountKeyUserId)); - if (! $accountKeyDoc->isEmpty()) { - $accountKeyUser = new User($accountKeyDoc->getArrayCopy()); + /** @var User $accountKeyUser */ + $accountKeyUser = $dbForPlatform->getAuthorization()->skip(fn () => $dbForPlatform->getDocument('users', $accountKeyUserId)); + if (! $accountKeyUser->isEmpty()) { $key = $accountKeyUser->find( key: 'secret', find: $accountKey, diff --git a/app/realtime.php b/app/realtime.php index 0a423f2bd5..1c453ce05b 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -518,7 +518,8 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats, $project = $consoleDatabase->getAuthorization()->skip(fn () => $consoleDatabase->getDocument('projects', $projectId)); $database = getProjectDB($project); - $user = new User($database->getDocument('users', $userId)->getArrayCopy()); + /** @var User $user */ + $user = $database->getDocument('users', $userId); $roles = $user->getRoles($database->getAuthorization()); $authorization = $realtime->connections[$connection]['authorization'] ?? null; @@ -887,7 +888,8 @@ $server->onMessage(function (int $connection, string $message) use ($server, $re $store->decode($message['data']['session']); - $user = new User($database->getDocument('users', $store->getProperty('id', ''))->getArrayCopy()); + /** @var User $user */ + $user = $database->getDocument('users', $store->getProperty('id', '')); /** * TODO: