Implemented query and order index checks
This commit is contained in:
parent
5ab38c0f98
commit
79f24098a4
|
@ -19,7 +19,6 @@ use Utopia\Database\Validator\Authorization;
|
|||
use Utopia\Database\Validator\Key;
|
||||
use Utopia\Database\Validator\Permissions;
|
||||
use Utopia\Database\Validator\QueryValidator;
|
||||
use Utopia\Database\Validator\Queries as QueriesValidator;
|
||||
use Utopia\Database\Validator\Structure;
|
||||
use Utopia\Database\Validator\UID;
|
||||
use Utopia\Database\Exception\Authorization as AuthorizationException;
|
||||
|
@ -31,6 +30,8 @@ use Appwrite\Network\Validator\Email;
|
|||
use Appwrite\Network\Validator\IP;
|
||||
use Appwrite\Network\Validator\URL;
|
||||
use Appwrite\Utopia\Database\Validator\CustomId;
|
||||
use Appwrite\Utopia\Database\Validator\Queries as QueriesValidator;
|
||||
use Appwrite\Utopia\Database\Validator\OrderAttributes as OrderAttributesValudator;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Detector\Detector;
|
||||
use Appwrite\Event\Event;
|
||||
|
@ -1742,6 +1743,13 @@ App::get('/v1/database/collections/:collectionId/documents')
|
|||
}
|
||||
}
|
||||
|
||||
if(!empty($orderAttributes)) {
|
||||
$validator = new OrderAttributesValudator($collection->getAttribute('attributes', []), $collection->getAttribute('indexes', []), true);
|
||||
if (!$validator->isValid($orderAttributes)) {
|
||||
throw new Exception($validator->getDescription(), 400, Exception::GENERAL_QUERY_INVALID);
|
||||
}
|
||||
}
|
||||
|
||||
$cursorDocument = null;
|
||||
if (!empty($cursor)) {
|
||||
$cursorDocument = $collection->getAttribute('permission') === 'collection'
|
||||
|
|
53
composer.lock
generated
53
composer.lock
generated
|
@ -300,20 +300,23 @@
|
|||
},
|
||||
{
|
||||
"name": "colinmollenhour/credis",
|
||||
"version": "v1.12.1",
|
||||
"version": "v1.12.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/colinmollenhour/credis.git",
|
||||
"reference": "c27faa11724229986335c23f4b6d0f1d8d6547fb"
|
||||
"reference": "77e6ede2e01c4cfaade114fe1e07d2f9756949f1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/colinmollenhour/credis/zipball/c27faa11724229986335c23f4b6d0f1d8d6547fb",
|
||||
"reference": "c27faa11724229986335c23f4b6d0f1d8d6547fb",
|
||||
"url": "https://api.github.com/repos/colinmollenhour/credis/zipball/77e6ede2e01c4cfaade114fe1e07d2f9756949f1",
|
||||
"reference": "77e6ede2e01c4cfaade114fe1e07d2f9756949f1",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.4.0"
|
||||
"php": ">=5.6.0"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-redis": "Improved performance for communicating with redis"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
|
@ -338,9 +341,9 @@
|
|||
"homepage": "https://github.com/colinmollenhour/credis",
|
||||
"support": {
|
||||
"issues": "https://github.com/colinmollenhour/credis/issues",
|
||||
"source": "https://github.com/colinmollenhour/credis/tree/v1.12.1"
|
||||
"source": "https://github.com/colinmollenhour/credis/tree/v1.12.2"
|
||||
},
|
||||
"time": "2020-11-06T16:09:14+00:00"
|
||||
"time": "2022-03-08T18:12:43+00:00"
|
||||
},
|
||||
{
|
||||
"name": "composer/package-versions-deprecated",
|
||||
|
@ -3491,16 +3494,16 @@
|
|||
},
|
||||
{
|
||||
"name": "felixfbecker/language-server-protocol",
|
||||
"version": "1.5.1",
|
||||
"version": "v1.5.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/felixfbecker/php-language-server-protocol.git",
|
||||
"reference": "9d846d1f5cf101deee7a61c8ba7caa0a975cd730"
|
||||
"reference": "6e82196ffd7c62f7794d778ca52b69feec9f2842"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/felixfbecker/php-language-server-protocol/zipball/9d846d1f5cf101deee7a61c8ba7caa0a975cd730",
|
||||
"reference": "9d846d1f5cf101deee7a61c8ba7caa0a975cd730",
|
||||
"url": "https://api.github.com/repos/felixfbecker/php-language-server-protocol/zipball/6e82196ffd7c62f7794d778ca52b69feec9f2842",
|
||||
"reference": "6e82196ffd7c62f7794d778ca52b69feec9f2842",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -3541,9 +3544,9 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/felixfbecker/php-language-server-protocol/issues",
|
||||
"source": "https://github.com/felixfbecker/php-language-server-protocol/tree/1.5.1"
|
||||
"source": "https://github.com/felixfbecker/php-language-server-protocol/tree/v1.5.2"
|
||||
},
|
||||
"time": "2021-02-22T14:02:09+00:00"
|
||||
"time": "2022-03-02T22:36:06+00:00"
|
||||
},
|
||||
{
|
||||
"name": "matthiasmullie/minify",
|
||||
|
@ -4118,16 +4121,16 @@
|
|||
},
|
||||
{
|
||||
"name": "phpdocumentor/type-resolver",
|
||||
"version": "1.6.0",
|
||||
"version": "1.6.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpDocumentor/TypeResolver.git",
|
||||
"reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706"
|
||||
"reference": "77a32518733312af16a44300404e945338981de3"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/93ebd0014cab80c4ea9f5e297ea48672f1b87706",
|
||||
"reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706",
|
||||
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/77a32518733312af16a44300404e945338981de3",
|
||||
"reference": "77a32518733312af16a44300404e945338981de3",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -4162,9 +4165,9 @@
|
|||
"description": "A PSR-5 based resolver of Class names, Types and Structural Element Names",
|
||||
"support": {
|
||||
"issues": "https://github.com/phpDocumentor/TypeResolver/issues",
|
||||
"source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.0"
|
||||
"source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.1"
|
||||
},
|
||||
"time": "2022-01-04T19:58:01+00:00"
|
||||
"time": "2022-03-15T21:29:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpspec/prophecy",
|
||||
|
@ -6324,16 +6327,16 @@
|
|||
},
|
||||
{
|
||||
"name": "twig/twig",
|
||||
"version": "v3.3.8",
|
||||
"version": "v3.3.9",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/twigphp/Twig.git",
|
||||
"reference": "972d8604a92b7054828b539f2febb0211dd5945c"
|
||||
"reference": "6ff9b0e440fa66f97f207e181c41340ddfa5683d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/twigphp/Twig/zipball/972d8604a92b7054828b539f2febb0211dd5945c",
|
||||
"reference": "972d8604a92b7054828b539f2febb0211dd5945c",
|
||||
"url": "https://api.github.com/repos/twigphp/Twig/zipball/6ff9b0e440fa66f97f207e181c41340ddfa5683d",
|
||||
"reference": "6ff9b0e440fa66f97f207e181c41340ddfa5683d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -6384,7 +6387,7 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/twigphp/Twig/issues",
|
||||
"source": "https://github.com/twigphp/Twig/tree/v3.3.8"
|
||||
"source": "https://github.com/twigphp/Twig/tree/v3.3.9"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -6396,7 +6399,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2022-02-04T06:59:48+00:00"
|
||||
"time": "2022-03-25T09:37:52+00:00"
|
||||
},
|
||||
{
|
||||
"name": "vimeo/psalm",
|
||||
|
|
25
src/Appwrite/Utopia/Database/Validator/OrderAttributes.php
Normal file
25
src/Appwrite/Utopia/Database/Validator/OrderAttributes.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
namespace Appwrite\Utopia\Database\Validator;
|
||||
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Validator\OrderAttributes as ValidatorOrderAttributes;
|
||||
|
||||
class OrderAttributes extends ValidatorOrderAttributes
|
||||
{
|
||||
/**
|
||||
* Expression constructor
|
||||
*
|
||||
* @param Document[] $attributes
|
||||
* @param Document[] $indexes
|
||||
* @param bool $strict
|
||||
*/
|
||||
public function __construct($attributes, $indexes, $strict)
|
||||
{
|
||||
// Remove failed/stuck/processing indexes
|
||||
$indexes = \array_filter($indexes, function($index) {
|
||||
return $index->getAttribute('status') === 'available';
|
||||
});
|
||||
|
||||
parent::__construct($attributes, $indexes, $strict);
|
||||
}
|
||||
}
|
25
src/Appwrite/Utopia/Database/Validator/Queries.php
Normal file
25
src/Appwrite/Utopia/Database/Validator/Queries.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
namespace Appwrite\Utopia\Database\Validator;
|
||||
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Validator\Queries as ValidatorQueries;
|
||||
|
||||
class Queries extends ValidatorQueries
|
||||
{
|
||||
/**
|
||||
* Expression constructor
|
||||
*
|
||||
* @param Document[] $attributes
|
||||
* @param Document[] $indexes
|
||||
* @param bool $strict
|
||||
*/
|
||||
public function __construct($attributes, $indexes, $strict)
|
||||
{
|
||||
// Remove failed/stuck/processing indexes
|
||||
$indexes = \array_filter($indexes, function($index) {
|
||||
return $index->getAttribute('status') === 'available';
|
||||
});
|
||||
|
||||
parent::__construct($attributes, $indexes, $strict);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue