1
0
Fork 0
mirror of synced 2024-05-20 20:52:36 +12:00

Removed first and last from internal functions

This commit is contained in:
Eldad Fux 2020-06-26 17:41:13 +03:00
parent bd073da05e
commit 7c2969b967
5 changed files with 34 additions and 34 deletions

View file

@ -80,9 +80,8 @@ $utopia->post('/v1/account')
}
}
$profile = $projectDB->getCollection([ // Get user by email address
$profile = $projectDB->getCollectionFirst([ // Get user by email address
'limit' => 1,
'first' => true,
'filters' => [
'$collection='.Database::SYSTEM_COLLECTION_USERS,
'email='.$email,
@ -163,9 +162,8 @@ $utopia->post('/v1/account/sessions')
->action(
function ($email, $password) use ($response, $request, $projectDB, $audit, $webhook) {
$protocol = Config::getParam('protocol');
$profile = $projectDB->getCollection([ // Get user by email address
$profile = $projectDB->getCollectionFirst([ // Get user by email address
'limit' => 1,
'first' => true,
'filters' => [
'$collection='.Database::SYSTEM_COLLECTION_USERS,
'email='.$email,
@ -414,9 +412,8 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect')
$projectDB->deleteDocument($current); //throw new Exception('User already logged in', 401);
}
$user = (empty($user->getId())) ? $projectDB->getCollection([ // Get user by provider id
$user = (empty($user->getId())) ? $projectDB->getCollectionFirst([ // Get user by provider id
'limit' => 1,
'first' => true,
'filters' => [
'$collection='.Database::SYSTEM_COLLECTION_USERS,
'oauth2'.\ucfirst($provider).'='.$oauth2ID,
@ -427,9 +424,8 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect')
$name = $oauth2->getUserName($accessToken);
$email = $oauth2->getUserEmail($accessToken);
$user = $projectDB->getCollection([ // Get user by provider email address
$user = $projectDB->getCollectionFirst([ // Get user by provider email address
'limit' => 1,
'first' => true,
'filters' => [
'$collection='.Database::SYSTEM_COLLECTION_USERS,
'email='.$email,
@ -797,9 +793,8 @@ $utopia->patch('/v1/account/email')
throw new Exception('Invalid credentials', 401);
}
$profile = $projectDB->getCollection([ // Get user by email address
$profile = $projectDB->getCollectionFirst([ // Get user by email address
'limit' => 1,
'first' => true,
'filters' => [
'$collection='.Database::SYSTEM_COLLECTION_USERS,
'email='.$email,
@ -1056,9 +1051,8 @@ $utopia->post('/v1/account/recovery')
->param('url', '', function () use ($clients) { return new Host($clients); }, 'URL to redirect the user back to your app from the recovery email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.')
->action(
function ($email, $url) use ($request, $response, $projectDB, $mail, $audit, $project) {
$profile = $projectDB->getCollection([ // Get user by email address
$profile = $projectDB->getCollectionFirst([ // Get user by email address
'limit' => 1,
'first' => true,
'filters' => [
'$collection='.Database::SYSTEM_COLLECTION_USERS,
'email='.$email,
@ -1161,9 +1155,8 @@ $utopia->put('/v1/account/recovery')
throw new Exception('Passwords must match', 400);
}
$profile = $projectDB->getCollection([ // Get user by email address
$profile = $projectDB->getCollectionFirst([ // Get user by email address
'limit' => 1,
'first' => true,
'filters' => [
'$collection='.Database::SYSTEM_COLLECTION_USERS,
'$id='.$userId,
@ -1311,9 +1304,8 @@ $utopia->put('/v1/account/verification')
->param('secret', '', function () { return new Text(256); }, 'Valid verification token.')
->action(
function ($userId, $secret) use ($response, $user, $projectDB, $audit) {
$profile = $projectDB->getCollection([ // Get user by email address
$profile = $projectDB->getCollectionFirst([ // Get user by email address
'limit' => 1,
'first' => true,
'filters' => [
'$collection='.Database::SYSTEM_COLLECTION_USERS,
'$id='.$userId,

View file

@ -232,9 +232,8 @@ $utopia->post('/v1/teams/:teamId/memberships')
],
]);
$invitee = $projectDB->getCollection([ // Get user by email address
$invitee = $projectDB->getCollectionFirst([ // Get user by email address
'limit' => 1,
'first' => true,
'filters' => [
'$collection='.Database::SYSTEM_COLLECTION_USERS,
'email='.$email,
@ -480,9 +479,8 @@ $utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status')
}
if (empty($user->getId())) {
$user = $projectDB->getCollection([ // Get user
$user = $projectDB->getCollectionFirst([ // Get user
'limit' => 1,
'first' => true,
'filters' => [
'$collection='.Database::SYSTEM_COLLECTION_USERS,
'$id='.$userId,

View file

@ -35,9 +35,8 @@ $utopia->post('/v1/users')
->param('name', '', function () { return new Text(100); }, 'User name.', true)
->action(
function ($email, $password, $name) use ($response, $projectDB) {
$profile = $projectDB->getCollection([ // Get user by email address
$profile = $projectDB->getCollectionFirst([ // Get user by email address
'limit' => 1,
'first' => true,
'filters' => [
'$collection='.Database::SYSTEM_COLLECTION_USERS,
'email='.$email,

View file

@ -77,7 +77,7 @@ class CertificatesV1
}
}
$certificate = $consoleDB->getCollection([
$certificate = $consoleDB->getCollectionFirst([
'limit' => 1,
'offset' => 0,
'orderField' => 'id',
@ -87,7 +87,6 @@ class CertificatesV1
'$collection='.Database::SYSTEM_COLLECTION_CERTIFICATES,
'domain='.$domain->get(),
],
'first' => true,
]);
// $condition = ($certificate

View file

@ -130,8 +130,6 @@ class Database
'orderField' => '$id',
'orderType' => 'ASC',
'orderCast' => 'int',
'first' => false,
'last' => false,
'filters' => [],
], $options);
@ -141,17 +139,31 @@ class Database
$node = new Document($node);
}
if ($options['first']) {
$results = \reset($results);
}
if ($options['last']) {
$results = \end($results);
}
return $results;
}
/**
* @param array $options
*
* @return Document
*/
public function getCollectionFirst(array $options)
{
$results = $this->getCollection($options);
return \reset($results);
}
/**
* @param array $options
*
* @return Document
*/
public function getCollectionLast(array $options)
{
$results = $this->getCollection($options);
return \end($results);
}
/**
* @param int $id
* @param bool $mock is mocked data allowed?