diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php index 1c5dec44dd..60c9e03c70 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php @@ -11,6 +11,7 @@ use Utopia\Database\Validator\Query\Filter; use Utopia\Database\Validator\Query\Limit; use Utopia\Database\Validator\Query\Offset; use Utopia\Database\Validator\Query\Order; +use Utopia\Database\Validator\Query\Select; class Base extends Queries { @@ -40,6 +41,7 @@ class Base extends Queries $allowedAttributesLookup[$attribute] = true; } + $allAttributes = []; $attributes = []; foreach ($collection['attributes'] as $attribute) { $key = $attribute['$id']; @@ -47,34 +49,44 @@ class Base extends Queries if (!isset($allowedAttributesLookup[$key])) { continue; } - - $attributes[] = new Document([ + + $attributeDocument = new Document([ 'key' => $key, 'type' => $attribute['type'], 'array' => $attribute['array'], ]); - } - $attributes[] = new Document([ - 'key' => '$id', - 'type' => Database::VAR_STRING, - 'array' => false, - ]); - $attributes[] = new Document([ - 'key' => '$createdAt', - 'type' => Database::VAR_DATETIME, - 'array' => false, - ]); - $attributes[] = new Document([ - 'key' => '$updatedAt', - 'type' => Database::VAR_DATETIME, - 'array' => false, - ]); - $attributes[] = new Document([ - 'key' => '$sequence', - 'type' => Database::VAR_INTEGER, - 'array' => false, - ]); + $attributes[] = $attributeDocument; + $allAttributes[] = $attributeDocument; + } + + $internalAttributes = [ + new Document([ + 'key' => '$id', + 'type' => Database::VAR_STRING, + 'array' => false, + ]), + new Document([ + 'key' => '$createdAt', + 'type' => Database::VAR_DATETIME, + 'array' => false, + ]), + new Document([ + 'key' => '$updatedAt', + 'type' => Database::VAR_DATETIME, + 'array' => false, + ]), + new Document([ + 'key' => '$sequence', + 'type' => Database::VAR_INTEGER, + 'array' => false, + ]) + ]; + + foreach($internalAttributes as $attribute) { + $attributes[] = $attribute; + $allAttributes[] = $attribute; + } $validators = [ new Limit(), @@ -83,7 +95,16 @@ class Base extends Queries new Filter($attributes, APP_DATABASE_QUERY_MAX_VALUES), new Order($attributes), ]; + + if($this->isSelectQueryAllowed()) { + $validators[] = new Select($allAttributes); + } parent::__construct($validators); } + + public function isSelectQueryAllowed(): bool + { + return true; + } } diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Deployments.php b/src/Appwrite/Utopia/Database/Validator/Queries/Deployments.php index 73631ecfb8..0d5565c968 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Deployments.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Deployments.php @@ -22,4 +22,9 @@ class Deployments extends Base { parent::__construct('deployments', self::ALLOWED_ATTRIBUTES); } + + public function isSelectQueryAllowed(): bool + { + return true; + } }