Merge pull request #8680 from appwrite/chore-update-databases-findone

Update Database lib
This commit is contained in:
Jake Barnby 2024-10-31 22:07:31 +13:00 committed by GitHub
commit 5be76494c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 63 additions and 68 deletions

View file

@ -332,7 +332,7 @@ App::post('/v1/account')
$identityWithMatchingEmail = $dbForProject->findOne('identities', [ $identityWithMatchingEmail = $dbForProject->findOne('identities', [
Query::equal('providerEmail', [$email]), Query::equal('providerEmail', [$email]),
]); ]);
if ($identityWithMatchingEmail !== false && !$identityWithMatchingEmail->isEmpty()) { if (!$identityWithMatchingEmail->isEmpty()) {
throw new Exception(Exception::GENERAL_BAD_REQUEST); /** Return a generic bad request to prevent exposing existing accounts */ throw new Exception(Exception::GENERAL_BAD_REQUEST); /** Return a generic bad request to prevent exposing existing accounts */
} }
@ -395,7 +395,7 @@ App::post('/v1/account')
$existingTarget = $dbForProject->findOne('targets', [ $existingTarget = $dbForProject->findOne('targets', [
Query::equal('identifier', [$email]), Query::equal('identifier', [$email]),
]); ]);
if ($existingTarget) { if (!$existingTarget->isEmpty()) {
$user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND); $user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND);
} }
} }
@ -834,7 +834,7 @@ App::post('/v1/account/sessions/email')
Query::equal('email', [$email]), Query::equal('email', [$email]),
]); ]);
if (!$profile || empty($profile->getAttribute('passwordUpdate')) || !Auth::passwordVerify($password, $profile->getAttribute('password'), $profile->getAttribute('hash'), $profile->getAttribute('hashOptions'))) { if ($profile->isEmpty() || empty($profile->getAttribute('passwordUpdate')) || !Auth::passwordVerify($password, $profile->getAttribute('password'), $profile->getAttribute('hash'), $profile->getAttribute('hashOptions'))) {
throw new Exception(Exception::USER_INVALID_CREDENTIALS); throw new Exception(Exception::USER_INVALID_CREDENTIALS);
} }
@ -1374,7 +1374,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
Query::equal('providerEmail', [$email]), Query::equal('providerEmail', [$email]),
Query::notEqual('userInternalId', $user->getInternalId()), Query::notEqual('userInternalId', $user->getInternalId()),
]); ]);
if (!empty($identityWithMatchingEmail)) { if (!$identityWithMatchingEmail->isEmpty()) {
throw new Exception(Exception::USER_ALREADY_EXISTS); throw new Exception(Exception::USER_ALREADY_EXISTS);
} }
@ -1405,7 +1405,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
Query::equal('provider', [$provider]), Query::equal('provider', [$provider]),
Query::equal('providerUid', [$oauth2ID]), Query::equal('providerUid', [$oauth2ID]),
]); ]);
if ($session !== false && !$session->isEmpty()) { if (!$session->isEmpty()) {
$user->setAttributes($dbForProject->getDocument('users', $session->getAttribute('userId'))->getArrayCopy()); $user->setAttributes($dbForProject->getDocument('users', $session->getAttribute('userId'))->getArrayCopy());
} }
} }
@ -1423,7 +1423,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
$userWithEmail = $dbForProject->findOne('users', [ $userWithEmail = $dbForProject->findOne('users', [
Query::equal('email', [$email]), Query::equal('email', [$email]),
]); ]);
if ($userWithEmail !== false && !$userWithEmail->isEmpty()) { if (!$userWithEmail->isEmpty()) {
$user->setAttributes($userWithEmail->getArrayCopy()); $user->setAttributes($userWithEmail->getArrayCopy());
} }
@ -1434,7 +1434,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
Query::equal('providerUid', [$oauth2ID]), Query::equal('providerUid', [$oauth2ID]),
]); ]);
if ($identity !== false && !$identity->isEmpty()) { if (!$identity->isEmpty()) {
$user = $dbForProject->getDocument('users', $identity->getAttribute('userId')); $user = $dbForProject->getDocument('users', $identity->getAttribute('userId'));
} }
} }
@ -1454,7 +1454,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
$identityWithMatchingEmail = $dbForProject->findOne('identities', [ $identityWithMatchingEmail = $dbForProject->findOne('identities', [
Query::equal('providerEmail', [$email]), Query::equal('providerEmail', [$email]),
]); ]);
if ($identityWithMatchingEmail !== false && !$identityWithMatchingEmail->isEmpty()) { if (!$identityWithMatchingEmail->isEmpty()) {
throw new Exception(Exception::GENERAL_BAD_REQUEST); /** Return a generic bad request to prevent exposing existing accounts */ throw new Exception(Exception::GENERAL_BAD_REQUEST); /** Return a generic bad request to prevent exposing existing accounts */
} }
@ -1517,7 +1517,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
Query::equal('provider', [$provider]), Query::equal('provider', [$provider]),
Query::equal('providerUid', [$oauth2ID]), Query::equal('providerUid', [$oauth2ID]),
]); ]);
if ($identity === false || $identity->isEmpty()) { if ($identity->isEmpty()) {
// Before creating the identity, check if the email is already associated with another user // Before creating the identity, check if the email is already associated with another user
$userId = $user->getId(); $userId = $user->getId();
@ -1801,7 +1801,7 @@ App::post('/v1/account/tokens/magic-url')
$isAppUser = Auth::isAppUser($roles); $isAppUser = Auth::isAppUser($roles);
$result = $dbForProject->findOne('users', [Query::equal('email', [$email])]); $result = $dbForProject->findOne('users', [Query::equal('email', [$email])]);
if ($result !== false && !$result->isEmpty()) { if (!$result->isEmpty()) {
$user->setAttributes($result->getArrayCopy()); $user->setAttributes($result->getArrayCopy());
} else { } else {
$limit = $project->getAttribute('auths', [])['limit'] ?? 0; $limit = $project->getAttribute('auths', [])['limit'] ?? 0;
@ -1818,7 +1818,7 @@ App::post('/v1/account/tokens/magic-url')
$identityWithMatchingEmail = $dbForProject->findOne('identities', [ $identityWithMatchingEmail = $dbForProject->findOne('identities', [
Query::equal('providerEmail', [$email]), Query::equal('providerEmail', [$email]),
]); ]);
if ($identityWithMatchingEmail !== false && !$identityWithMatchingEmail->isEmpty()) { if (!$identityWithMatchingEmail->isEmpty()) {
throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS); throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS);
} }
@ -2042,7 +2042,7 @@ App::post('/v1/account/tokens/email')
$isAppUser = Auth::isAppUser($roles); $isAppUser = Auth::isAppUser($roles);
$result = $dbForProject->findOne('users', [Query::equal('email', [$email])]); $result = $dbForProject->findOne('users', [Query::equal('email', [$email])]);
if ($result !== false && !$result->isEmpty()) { if (!$result->isEmpty()) {
$user->setAttributes($result->getArrayCopy()); $user->setAttributes($result->getArrayCopy());
} else { } else {
$limit = $project->getAttribute('auths', [])['limit'] ?? 0; $limit = $project->getAttribute('auths', [])['limit'] ?? 0;
@ -2059,7 +2059,7 @@ App::post('/v1/account/tokens/email')
$identityWithMatchingEmail = $dbForProject->findOne('identities', [ $identityWithMatchingEmail = $dbForProject->findOne('identities', [
Query::equal('providerEmail', [$email]), Query::equal('providerEmail', [$email]),
]); ]);
if ($identityWithMatchingEmail !== false && !$identityWithMatchingEmail->isEmpty()) { if (!$identityWithMatchingEmail->isEmpty()) {
throw new Exception(Exception::GENERAL_BAD_REQUEST); /** Return a generic bad request to prevent exposing existing accounts */ throw new Exception(Exception::GENERAL_BAD_REQUEST); /** Return a generic bad request to prevent exposing existing accounts */
} }
@ -2329,7 +2329,7 @@ App::post('/v1/account/tokens/phone')
$isAppUser = Auth::isAppUser($roles); $isAppUser = Auth::isAppUser($roles);
$result = $dbForProject->findOne('users', [Query::equal('phone', [$phone])]); $result = $dbForProject->findOne('users', [Query::equal('phone', [$phone])]);
if ($result !== false && !$result->isEmpty()) { if (!$result->isEmpty()) {
$user->setAttributes($result->getArrayCopy()); $user->setAttributes($result->getArrayCopy());
} else { } else {
$limit = $project->getAttribute('auths', [])['limit'] ?? 0; $limit = $project->getAttribute('auths', [])['limit'] ?? 0;
@ -2386,7 +2386,7 @@ App::post('/v1/account/tokens/phone')
$existingTarget = $dbForProject->findOne('targets', [ $existingTarget = $dbForProject->findOne('targets', [
Query::equal('identifier', [$phone]), Query::equal('identifier', [$phone]),
]); ]);
$user->setAttribute('targets', [...$user->getAttribute('targets', []), $existingTarget]); $user->setAttribute('targets', [...$user->getAttribute('targets', []), $existingTarget->isEmpty() ? false : $existingTarget]);
} }
$dbForProject->purgeCachedDocument('users', $user->getId()); $dbForProject->purgeCachedDocument('users', $user->getId());
} }
@ -2753,7 +2753,7 @@ App::patch('/v1/account/email')
Query::equal('providerEmail', [$email]), Query::equal('providerEmail', [$email]),
Query::notEqual('userInternalId', $user->getInternalId()), Query::notEqual('userInternalId', $user->getInternalId()),
]); ]);
if ($identityWithMatchingEmail !== false && !$identityWithMatchingEmail->isEmpty()) { if (!$identityWithMatchingEmail->isEmpty()) {
throw new Exception(Exception::GENERAL_BAD_REQUEST); /** Return a generic bad request to prevent exposing existing accounts */ throw new Exception(Exception::GENERAL_BAD_REQUEST); /** Return a generic bad request to prevent exposing existing accounts */
} }
@ -2774,7 +2774,7 @@ App::patch('/v1/account/email')
Query::equal('identifier', [$email]), Query::equal('identifier', [$email]),
])); ]));
if ($target instanceof Document && !$target->isEmpty()) { if (!$target->isEmpty()) {
throw new Exception(Exception::USER_TARGET_ALREADY_EXISTS); throw new Exception(Exception::USER_TARGET_ALREADY_EXISTS);
} }
@ -2840,7 +2840,7 @@ App::patch('/v1/account/phone')
Query::equal('identifier', [$phone]), Query::equal('identifier', [$phone]),
])); ]));
if ($target instanceof Document && !$target->isEmpty()) { if (!$target->isEmpty()) {
throw new Exception(Exception::USER_TARGET_ALREADY_EXISTS); throw new Exception(Exception::USER_TARGET_ALREADY_EXISTS);
} }
@ -2999,7 +2999,7 @@ App::post('/v1/account/recovery')
Query::equal('email', [$email]), Query::equal('email', [$email]),
]); ]);
if (!$profile) { if ($profile->isEmpty()) {
throw new Exception(Exception::USER_NOT_FOUND); throw new Exception(Exception::USER_NOT_FOUND);
} }

View file

@ -2324,7 +2324,7 @@ App::delete('/v1/functions/:functionId/executions/:executionId')
Query::equal('active', [true]), Query::equal('active', [true]),
]); ]);
if ($schedule && !$schedule->isEmpty()) { if (!$schedule->isEmpty()) {
$schedule $schedule
->setAttribute('resourceUpdatedAt', DateTime::now()) ->setAttribute('resourceUpdatedAt', DateTime::now())
->setAttribute('active', false); ->setAttribute('active', false);

View file

@ -121,7 +121,7 @@ App::post('/v1/migrations/firebase/oauth')
Query::equal('provider', ['firebase']), Query::equal('provider', ['firebase']),
Query::equal('userInternalId', [$user->getInternalId()]), Query::equal('userInternalId', [$user->getInternalId()]),
]); ]);
if ($identity === false || $identity->isEmpty()) { if ($identity->isEmpty()) {
throw new Exception(Exception::USER_IDENTITY_NOT_FOUND); throw new Exception(Exception::USER_IDENTITY_NOT_FOUND);
} }
@ -576,7 +576,7 @@ App::get('/v1/migrations/firebase/report/oauth')
Query::equal('userInternalId', [$user->getInternalId()]), Query::equal('userInternalId', [$user->getInternalId()]),
]); ]);
if ($identity === false || $identity->isEmpty()) { if ($identity->isEmpty()) {
throw new Exception(Exception::USER_IDENTITY_NOT_FOUND); throw new Exception(Exception::USER_IDENTITY_NOT_FOUND);
} }
@ -751,13 +751,13 @@ App::get('/v1/migrations/firebase/redirect')
Query::equal('providerEmail', [$email]), Query::equal('providerEmail', [$email]),
]); ]);
if ($identity !== false && !$identity->isEmpty()) { if (!$identity->isEmpty()) {
if ($identity->getAttribute('userInternalId', '') !== $user->getInternalId()) { if ($identity->getAttribute('userInternalId', '') !== $user->getInternalId()) {
throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS); throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS);
} }
} }
if ($identity !== false && !$identity->isEmpty()) { if (!$identity->isEmpty()) {
$identity = $identity $identity = $identity
->setAttribute('providerAccessToken', $accessToken) ->setAttribute('providerAccessToken', $accessToken)
->setAttribute('providerRefreshToken', $refreshToken) ->setAttribute('providerRefreshToken', $refreshToken)
@ -820,7 +820,7 @@ App::get('/v1/migrations/firebase/projects')
Query::equal('userInternalId', [$user->getInternalId()]), Query::equal('userInternalId', [$user->getInternalId()]),
]); ]);
if ($identity === false || $identity->isEmpty()) { if ($identity->isEmpty()) {
throw new Exception(Exception::USER_IDENTITY_NOT_FOUND); throw new Exception(Exception::USER_IDENTITY_NOT_FOUND);
} }
@ -900,7 +900,7 @@ App::get('/v1/migrations/firebase/deauthorize')
Query::equal('userInternalId', [$user->getInternalId()]), Query::equal('userInternalId', [$user->getInternalId()]),
]); ]);
if ($identity === false || $identity->isEmpty()) { if ($identity->isEmpty()) {
throw new Exception(Exception::GENERAL_ACCESS_FORBIDDEN, 'Not authenticated with Firebase'); //TODO: Replace with USER_IDENTITY_NOT_FOUND throw new Exception(Exception::GENERAL_ACCESS_FORBIDDEN, 'Not authenticated with Firebase'); //TODO: Replace with USER_IDENTITY_NOT_FOUND
} }

View file

@ -1060,7 +1060,7 @@ App::get('/v1/projects/:projectId/webhooks/:webhookId')
Query::equal('projectInternalId', [$project->getInternalId()]), Query::equal('projectInternalId', [$project->getInternalId()]),
]); ]);
if ($webhook === false || $webhook->isEmpty()) { if ($webhook->isEmpty()) {
throw new Exception(Exception::WEBHOOK_NOT_FOUND); throw new Exception(Exception::WEBHOOK_NOT_FOUND);
} }
@ -1103,7 +1103,7 @@ App::put('/v1/projects/:projectId/webhooks/:webhookId')
Query::equal('projectInternalId', [$project->getInternalId()]), Query::equal('projectInternalId', [$project->getInternalId()]),
]); ]);
if ($webhook === false || $webhook->isEmpty()) { if ($webhook->isEmpty()) {
throw new Exception(Exception::WEBHOOK_NOT_FOUND); throw new Exception(Exception::WEBHOOK_NOT_FOUND);
} }
@ -1153,7 +1153,7 @@ App::patch('/v1/projects/:projectId/webhooks/:webhookId/signature')
Query::equal('projectInternalId', [$project->getInternalId()]), Query::equal('projectInternalId', [$project->getInternalId()]),
]); ]);
if ($webhook === false || $webhook->isEmpty()) { if ($webhook->isEmpty()) {
throw new Exception(Exception::WEBHOOK_NOT_FOUND); throw new Exception(Exception::WEBHOOK_NOT_FOUND);
} }
@ -1191,7 +1191,7 @@ App::delete('/v1/projects/:projectId/webhooks/:webhookId')
Query::equal('projectInternalId', [$project->getInternalId()]), Query::equal('projectInternalId', [$project->getInternalId()]),
]); ]);
if ($webhook === false || $webhook->isEmpty()) { if ($webhook->isEmpty()) {
throw new Exception(Exception::WEBHOOK_NOT_FOUND); throw new Exception(Exception::WEBHOOK_NOT_FOUND);
} }
@ -1313,7 +1313,7 @@ App::get('/v1/projects/:projectId/keys/:keyId')
Query::equal('projectInternalId', [$project->getInternalId()]), Query::equal('projectInternalId', [$project->getInternalId()]),
]); ]);
if ($key === false || $key->isEmpty()) { if ($key->isEmpty()) {
throw new Exception(Exception::KEY_NOT_FOUND); throw new Exception(Exception::KEY_NOT_FOUND);
} }
@ -1350,7 +1350,7 @@ App::put('/v1/projects/:projectId/keys/:keyId')
Query::equal('projectInternalId', [$project->getInternalId()]), Query::equal('projectInternalId', [$project->getInternalId()]),
]); ]);
if ($key === false || $key->isEmpty()) { if ($key->isEmpty()) {
throw new Exception(Exception::KEY_NOT_FOUND); throw new Exception(Exception::KEY_NOT_FOUND);
} }
@ -1392,7 +1392,7 @@ App::delete('/v1/projects/:projectId/keys/:keyId')
Query::equal('projectInternalId', [$project->getInternalId()]), Query::equal('projectInternalId', [$project->getInternalId()]),
]); ]);
if ($key === false || $key->isEmpty()) { if ($key->isEmpty()) {
throw new Exception(Exception::KEY_NOT_FOUND); throw new Exception(Exception::KEY_NOT_FOUND);
} }
@ -1550,7 +1550,7 @@ App::get('/v1/projects/:projectId/platforms/:platformId')
Query::equal('projectInternalId', [$project->getInternalId()]), Query::equal('projectInternalId', [$project->getInternalId()]),
]); ]);
if ($platform === false || $platform->isEmpty()) { if ($platform->isEmpty()) {
throw new Exception(Exception::PLATFORM_NOT_FOUND); throw new Exception(Exception::PLATFORM_NOT_FOUND);
} }
@ -1587,7 +1587,7 @@ App::put('/v1/projects/:projectId/platforms/:platformId')
Query::equal('projectInternalId', [$project->getInternalId()]), Query::equal('projectInternalId', [$project->getInternalId()]),
]); ]);
if ($platform === false || $platform->isEmpty()) { if ($platform->isEmpty()) {
throw new Exception(Exception::PLATFORM_NOT_FOUND); throw new Exception(Exception::PLATFORM_NOT_FOUND);
} }
@ -1631,7 +1631,7 @@ App::delete('/v1/projects/:projectId/platforms/:platformId')
Query::equal('projectInternalId', [$project->getInternalId()]), Query::equal('projectInternalId', [$project->getInternalId()]),
]); ]);
if ($platform === false || $platform->isEmpty()) { if ($platform->isEmpty()) {
throw new Exception(Exception::PLATFORM_NOT_FOUND); throw new Exception(Exception::PLATFORM_NOT_FOUND);
} }

View file

@ -64,7 +64,7 @@ App::post('/v1/proxy/rules')
Query::equal('domain', [$domain]), Query::equal('domain', [$domain]),
]); ]);
if ($document && !$document->isEmpty()) { if (!$document->isEmpty()) {
if ($document->getAttribute('projectId') === $project->getId()) { if ($document->getAttribute('projectId') === $project->getId()) {
$resourceType = $document->getAttribute('resourceType'); $resourceType = $document->getAttribute('resourceType');
$resourceId = $document->getAttribute('resourceId'); $resourceId = $document->getAttribute('resourceId');

View file

@ -467,17 +467,17 @@ App::post('/v1/teams/:teamId/memberships')
$name = empty($name) ? $invitee->getAttribute('name', '') : $name; $name = empty($name) ? $invitee->getAttribute('name', '') : $name;
} elseif (!empty($email)) { } elseif (!empty($email)) {
$invitee = $dbForProject->findOne('users', [Query::equal('email', [$email])]); // Get user by email address $invitee = $dbForProject->findOne('users', [Query::equal('email', [$email])]); // Get user by email address
if (!empty($invitee) && !empty($phone) && $invitee->getAttribute('phone', '') !== $phone) { if (!$invitee->isEmpty() && !empty($phone) && $invitee->getAttribute('phone', '') !== $phone) {
throw new Exception(Exception::USER_ALREADY_EXISTS, 'Given email and phone doesn\'t match', 409); throw new Exception(Exception::USER_ALREADY_EXISTS, 'Given email and phone doesn\'t match', 409);
} }
} elseif (!empty($phone)) { } elseif (!empty($phone)) {
$invitee = $dbForProject->findOne('users', [Query::equal('phone', [$phone])]); $invitee = $dbForProject->findOne('users', [Query::equal('phone', [$phone])]);
if (!empty($invitee) && !empty($email) && $invitee->getAttribute('email', '') !== $email) { if (!$invitee->isEmpty() && !empty($email) && $invitee->getAttribute('email', '') !== $email) {
throw new Exception(Exception::USER_ALREADY_EXISTS, 'Given phone and email doesn\'t match', 409); throw new Exception(Exception::USER_ALREADY_EXISTS, 'Given phone and email doesn\'t match', 409);
} }
} }
if (empty($invitee)) { // Create new user if no user with same email found if ($invitee->isEmpty()) { // Create new user if no user with same email found
$limit = $project->getAttribute('auths', [])['limit'] ?? 0; $limit = $project->getAttribute('auths', [])['limit'] ?? 0;
if (!$isPrivilegedUser && !$isAppUser && $limit !== 0 && $project->getId() !== 'console') { // check users limit, console invites are allways allowed. if (!$isPrivilegedUser && !$isAppUser && $limit !== 0 && $project->getId() !== 'console') { // check users limit, console invites are allways allowed.
@ -492,7 +492,7 @@ App::post('/v1/teams/:teamId/memberships')
$identityWithMatchingEmail = $dbForProject->findOne('identities', [ $identityWithMatchingEmail = $dbForProject->findOne('identities', [
Query::equal('providerEmail', [$email]), Query::equal('providerEmail', [$email]),
]); ]);
if ($identityWithMatchingEmail !== false && !$identityWithMatchingEmail->isEmpty()) { if (!$identityWithMatchingEmail->isEmpty()) {
throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS); throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS);
} }

View file

@ -64,7 +64,7 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e
$identityWithMatchingEmail = $dbForProject->findOne('identities', [ $identityWithMatchingEmail = $dbForProject->findOne('identities', [
Query::equal('providerEmail', [$email]), Query::equal('providerEmail', [$email]),
]); ]);
if ($identityWithMatchingEmail !== false && !$identityWithMatchingEmail->isEmpty()) { if (!$identityWithMatchingEmail->isEmpty()) {
throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS); throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS);
} }
} }
@ -141,7 +141,7 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e
$existingTarget = $dbForProject->findOne('targets', [ $existingTarget = $dbForProject->findOne('targets', [
Query::equal('identifier', [$email]), Query::equal('identifier', [$email]),
]); ]);
if ($existingTarget) { if (!$existingTarget->isEmpty()) {
$user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND); $user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND);
} }
} }
@ -165,7 +165,7 @@ function createUser(string $hash, mixed $hashOptions, string $userId, ?string $e
$existingTarget = $dbForProject->findOne('targets', [ $existingTarget = $dbForProject->findOne('targets', [
Query::equal('identifier', [$phone]), Query::equal('identifier', [$phone]),
]); ]);
if ($existingTarget) { if (!$existingTarget->isEmpty()) {
$user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND); $user->setAttribute('targets', $existingTarget, Document::SET_TYPE_APPEND);
} }
} }
@ -1232,7 +1232,7 @@ App::patch('/v1/users/:userId/email')
Query::equal('providerEmail', [$email]), Query::equal('providerEmail', [$email]),
Query::notEqual('userInternalId', $user->getInternalId()), Query::notEqual('userInternalId', $user->getInternalId()),
]); ]);
if ($identityWithMatchingEmail !== false && !$identityWithMatchingEmail->isEmpty()) { if (!$identityWithMatchingEmail->isEmpty()) {
throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS); throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS);
} }

View file

@ -110,7 +110,7 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId
Query::orderDesc('$createdAt'), Query::orderDesc('$createdAt'),
])); ]));
if ($latestComment !== false && !$latestComment->isEmpty()) { if (!$latestComment->isEmpty()) {
$latestCommentId = $latestComment->getAttribute('providerCommentId', ''); $latestCommentId = $latestComment->getAttribute('providerCommentId', '');
$comment = new Comment(); $comment = new Comment();
$comment->parseComment($github->getComment($owner, $repositoryName, $latestCommentId)); $comment->parseComment($github->getComment($owner, $repositoryName, $latestCommentId));
@ -371,13 +371,11 @@ App::get('/v1/vcs/github/callback')
$identity = $dbForConsole->findOne('identities', [ $identity = $dbForConsole->findOne('identities', [
Query::equal('providerEmail', [$email]), Query::equal('providerEmail', [$email]),
]); ]);
if ($identity !== false && !$identity->isEmpty()) { if (!$identity->isEmpty()) {
if ($identity->getAttribute('userInternalId', '') !== $user->getInternalId()) { if ($identity->getAttribute('userInternalId', '') !== $user->getInternalId()) {
throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS); throw new Exception(Exception::USER_EMAIL_ALREADY_EXISTS);
} }
}
if ($identity !== false && !$identity->isEmpty()) {
$identity = $identity $identity = $identity
->setAttribute('providerAccessToken', $accessToken) ->setAttribute('providerAccessToken', $accessToken)
->setAttribute('providerRefreshToken', $refreshToken) ->setAttribute('providerRefreshToken', $refreshToken)
@ -418,7 +416,7 @@ App::get('/v1/vcs/github/callback')
Query::equal('projectInternalId', [$projectInternalId]) Query::equal('projectInternalId', [$projectInternalId])
]); ]);
if ($installation === false || $installation->isEmpty()) { if ($installation->isEmpty()) {
$teamId = $project->getAttribute('teamId', ''); $teamId = $project->getAttribute('teamId', '');
$installation = new Document([ $installation = new Document([
@ -726,7 +724,7 @@ App::post('/v1/vcs/github/installations/:installationId/providerRepositories')
Query::equal('provider', ['github']), Query::equal('provider', ['github']),
Query::equal('userInternalId', [$user->getInternalId()]), Query::equal('userInternalId', [$user->getInternalId()]),
]); ]);
if ($identity === false || $identity->isEmpty()) { if ($identity->isEmpty()) {
throw new Exception(Exception::USER_IDENTITY_NOT_FOUND); throw new Exception(Exception::USER_IDENTITY_NOT_FOUND);
} }

View file

@ -519,7 +519,7 @@ App::init()
$mainDomain = $envDomain; $mainDomain = $envDomain;
} else { } else {
$domainDocument = $dbForConsole->findOne('rules', [Query::orderAsc('$id')]); $domainDocument = $dbForConsole->findOne('rules', [Query::orderAsc('$id')]);
$mainDomain = $domainDocument ? $domainDocument->getAttribute('domain') : $domain->get(); $mainDomain = !$domainDocument->isEmpty() ? $domainDocument->getAttribute('domain') : $domain->get();
} }
if ($mainDomain !== $domain->get()) { if ($mainDomain !== $domain->get()) {
@ -529,7 +529,7 @@ App::init()
Query::equal('domain', [$domain->get()]) Query::equal('domain', [$domain->get()])
]); ]);
if (!$domainDocument) { if ($domainDocument->isEmpty()) {
$domainDocument = new Document([ $domainDocument = new Document([
'domain' => $domain->get(), 'domain' => $domain->get(),
'resourceType' => 'api', 'resourceType' => 'api',

View file

@ -1812,9 +1812,6 @@ App::setResource('team', function (Document $project, Database $dbForConsole, Ap
]); ]);
}); });
if (!$team) {
$team = new Document([]);
}
return $team; return $team;
}, ['project', 'dbForConsole', 'utopia', 'request']); }, ['project', 'dbForConsole', 'utopia', 'request']);

View file

@ -51,7 +51,7 @@
"utopia-php/cache": "0.10.*", "utopia-php/cache": "0.10.*",
"utopia-php/cli": "0.15.*", "utopia-php/cli": "0.15.*",
"utopia-php/config": "0.2.*", "utopia-php/config": "0.2.*",
"utopia-php/database": "0.53.8", "utopia-php/database": "0.53.9",
"utopia-php/domains": "0.5.*", "utopia-php/domains": "0.5.*",
"utopia-php/dsn": "0.2.1", "utopia-php/dsn": "0.2.1",
"utopia-php/framework": "0.33.*", "utopia-php/framework": "0.33.*",

14
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "18505aa5baca1170e7cbdbb2a355b173", "content-hash": "1529d4abfe0432b2d9c838705220ed4a",
"packages": [ "packages": [
{ {
"name": "adhocore/jwt", "name": "adhocore/jwt",
@ -1724,16 +1724,16 @@
}, },
{ {
"name": "utopia-php/database", "name": "utopia-php/database",
"version": "0.53.8", "version": "0.53.9",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/utopia-php/database.git", "url": "https://github.com/utopia-php/database.git",
"reference": "f4f9297d633b9f8407c6261535549bfd6024a468" "reference": "19969d2c6d29b5d1cbf4cb1a33e18017a54f30e3"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/utopia-php/database/zipball/f4f9297d633b9f8407c6261535549bfd6024a468", "url": "https://api.github.com/repos/utopia-php/database/zipball/19969d2c6d29b5d1cbf4cb1a33e18017a54f30e3",
"reference": "f4f9297d633b9f8407c6261535549bfd6024a468", "reference": "19969d2c6d29b5d1cbf4cb1a33e18017a54f30e3",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1774,9 +1774,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/utopia-php/database/issues", "issues": "https://github.com/utopia-php/database/issues",
"source": "https://github.com/utopia-php/database/tree/0.53.8" "source": "https://github.com/utopia-php/database/tree/0.53.9"
}, },
"time": "2024-10-16T08:16:33+00:00" "time": "2024-10-31T08:18:52+00:00"
}, },
{ {
"name": "utopia-php/domains", "name": "utopia-php/domains",

View file

@ -126,7 +126,7 @@ class Certificates extends Action
$certificate = $dbForConsole->findOne('certificates', [Query::equal('domain', [$domain->get()])]); $certificate = $dbForConsole->findOne('certificates', [Query::equal('domain', [$domain->get()])]);
// If we don't have certificate for domain yet, let's create new document. At the end we save it // If we don't have certificate for domain yet, let's create new document. At the end we save it
if (!$certificate) { if ($certificate->isEmpty()) {
$certificate = new Document(); $certificate = new Document();
$certificate->setAttribute('domain', $domain->get()); $certificate->setAttribute('domain', $domain->get());
} }
@ -216,7 +216,7 @@ class Certificates extends Action
{ {
// Check if update or insert required // Check if update or insert required
$certificateDocument = $dbForConsole->findOne('certificates', [Query::equal('domain', [$domain])]); $certificateDocument = $dbForConsole->findOne('certificates', [Query::equal('domain', [$domain])]);
if (!empty($certificateDocument) && !$certificateDocument->isEmpty()) { if (!$certificateDocument->isEmpty()) {
// Merge new data with current data // Merge new data with current data
$certificate = new Document(\array_merge($certificateDocument->getArrayCopy(), $certificate->getArrayCopy())); $certificate = new Document(\array_merge($certificateDocument->getArrayCopy(), $certificate->getArrayCopy()));
$certificate = $dbForConsole->updateDocument('certificates', $certificate->getId(), $certificate); $certificate = $dbForConsole->updateDocument('certificates', $certificate->getId(), $certificate);
@ -482,7 +482,7 @@ class Certificates extends Action
Query::equal('domain', [$domain]), Query::equal('domain', [$domain]),
]); ]);
if ($rule !== false && !$rule->isEmpty()) { if (!$rule->isEmpty()) {
$rule->setAttribute('certificateId', $certificateId); $rule->setAttribute('certificateId', $certificateId);
$rule->setAttribute('status', $success ? 'verified' : 'unverified'); $rule->setAttribute('status', $success ? 'verified' : 'unverified');
$dbForConsole->updateDocument('rules', $rule->getId(), $rule); $dbForConsole->updateDocument('rules', $rule->getId(), $rule);

View file

@ -178,7 +178,7 @@ class Messaging extends Action
Query::equal('type', [$providerType]), Query::equal('type', [$providerType]),
]); ]);
if ($default === false || $default->isEmpty()) { if ($default->isEmpty()) {
$dbForProject->updateDocument('messages', $message->getId(), $message->setAttributes([ $dbForProject->updateDocument('messages', $message->getId(), $message->setAttributes([
'status' => MessageStatus::FAILED, 'status' => MessageStatus::FAILED,
'deliveryErrors' => ['No enabled provider found.'] 'deliveryErrors' => ['No enabled provider found.']