diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index 1cf78b07e3..637e158a45 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -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 OrderAttributesValidator; 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 OrderAttributesValidator($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' diff --git a/src/Appwrite/Utopia/Database/Validator/OrderAttributes.php b/src/Appwrite/Utopia/Database/Validator/OrderAttributes.php new file mode 100644 index 0000000000..628615f006 --- /dev/null +++ b/src/Appwrite/Utopia/Database/Validator/OrderAttributes.php @@ -0,0 +1,25 @@ +getAttribute('status') === 'available'; + }); + + parent::__construct($attributes, $indexes, $strict); + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Database/Validator/Queries.php b/src/Appwrite/Utopia/Database/Validator/Queries.php new file mode 100644 index 0000000000..73bf04be40 --- /dev/null +++ b/src/Appwrite/Utopia/Database/Validator/Queries.php @@ -0,0 +1,25 @@ +getAttribute('status') === 'available'; + }); + + parent::__construct($attributes, $indexes, $strict); + } +} \ No newline at end of file