diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 70f36242aa..eff7bc15cc 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -2750,12 +2750,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') } $filterQueries = Query::groupByType($queries)['filters']; - // todo: temporary fix until Utopia will be ready !!!! - foreach ($filterQueries as $key => $query) { - if (\str_contains($query->getAttribute(), '.')) { - unset($filterQueries[$key]); - } - } + if ($documentSecurity && !$valid) { $documents = $dbForProject->find('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $queries); $total = $dbForProject->count('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $filterQueries, APP_LIMIT_COUNT); diff --git a/app/workers/databases.php b/app/workers/databases.php index b1649d5568..c5743cc56b 100644 --- a/app/workers/databases.php +++ b/app/workers/databases.php @@ -95,26 +95,30 @@ class DatabaseV1 extends Worker $project = $dbForConsole->getDocument('projects', $projectId); try { - if ($type === Database::VAR_RELATIONSHIP) { - $relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $options['relatedCollection']); - if ($relatedCollection->isEmpty()) { - throw new Exception('Missing collection'); - } - if ( - !$dbForProject->createRelationship( - collection: 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), - relatedCollection: 'database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId(), - type: $options['relationType'], - twoWay: $options['twoWay'], - id: $key, - twoWayKey: $options['twoWayKey'], - onDelete: $options['onDelete'], - ) - ) { - throw new Exception('Failed to create Attribute'); - } - } elseif (!$dbForProject->createAttribute('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key, $type, $size, $required, $default, $signed, $array, $format, $formatOptions, $filters)) { - throw new Exception('Failed to create Attribute'); + switch ($type) { + case Database::VAR_RELATIONSHIP: + $relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $options['relatedCollection']); + if ($relatedCollection->isEmpty()) { + throw new Exception('Collection not found'); + } + if ( + !$dbForProject->createRelationship( + collection: 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), + relatedCollection: 'database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId(), + type: $options['relationType'], + twoWay: $options['twoWay'], + id: $key, + twoWayKey: $options['twoWayKey'], + onDelete: $options['onDelete'], + ) + ) { + throw new Exception('Failed to create Attribute'); + } + break; + default: + if (!$dbForProject->createAttribute('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key, $type, $size, $required, $default, $signed, $array, $format, $formatOptions, $filters)) { + throw new Exception('Failed to create Attribute'); + } } $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'available')); @@ -151,6 +155,7 @@ class DatabaseV1 extends Worker * @param Document $collection * @param Document $attribute * @param string $projectId + * @throws Throwable */ protected function deleteAttribute(Document $database, Document $collection, Document $attribute, string $projectId): void { @@ -177,12 +182,16 @@ class DatabaseV1 extends Worker try { if ($status !== 'failed') { - if ($type === Database::VAR_RELATIONSHIP) { - if (!$dbForProject->deleteRelationship('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key)) { - throw new Exception('Failed to delete Attribute'); - } - } elseif (!$dbForProject->deleteAttribute('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key)) { - throw new Exception('Failed to delete Attribute'); + switch ($type) { + case Database::VAR_RELATIONSHIP: + if (!$dbForProject->deleteRelationship('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key)) { + throw new Exception('Failed to delete Attribute'); + } + break; + default: + if (!$dbForProject->deleteAttribute('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key)) { + throw new Exception('Failed to delete Attribute'); + } } } $dbForProject->deleteDocument('attributes', $attribute->getId()); diff --git a/docker-compose.yml b/docker-compose.yml index 8eb5862d8d..8adb19e375 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -83,8 +83,6 @@ services: - ./docs:/usr/src/code/docs - ./public:/usr/src/code/public - ./src:/usr/src/code/src - - ./vendor/utopia-php/framework:/usr/src/code/vendor/utopia-php/framework - - ./vendor/utopia-php/database:/usr/src/code/vendor/utopia-php/database depends_on: - mariadb - redis @@ -345,8 +343,6 @@ services: volumes: - ./app:/usr/src/code/app - ./src:/usr/src/code/src - - ./vendor/utopia-php/database:/usr/src/code/vendor/utopia-php/database - - ./vendor/utopia-php/framework:/usr/src/code/vendor/utopia-php/framework depends_on: - redis - mariadb diff --git a/src/Appwrite/Utopia/Response/Model/AttributeRelationship.php b/src/Appwrite/Utopia/Response/Model/AttributeRelationship.php index 71b2039aea..d743eccf83 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributeRelationship.php +++ b/src/Appwrite/Utopia/Response/Model/AttributeRelationship.php @@ -11,12 +11,6 @@ class AttributeRelationship extends Attribute parent::__construct(); $this - ->addRule('default', [ - 'type' => self::TYPE_STRING, - 'description' => 'Default value for attribute when not provided. Only null is optional', - 'default' => null, - 'example' => '', - ]) ->addRule('relatedCollection', [ 'type' => self::TYPE_STRING, 'description' => 'The Id of the related collection', @@ -25,26 +19,26 @@ class AttributeRelationship extends Attribute ]) ->addRule('relationType', [ 'type' => self::TYPE_STRING, - 'description' => 'The type of the relationship ', - 'default' => null, + 'description' => 'The type of the relationship', + 'default' => '', 'example' => 'oneToOne|oneToMany|manyToOne|manyToMany', ]) ->addRule('twoWay', [ 'type' => self::TYPE_BOOLEAN, 'description' => 'Is the relationship two-way?', - 'default' => null, - 'example' => 'relationship', + 'default' => false, + 'example' => false, ]) ->addRule('twoWayKey', [ 'type' => self::TYPE_STRING, 'description' => 'The key of the two-way relationship', - 'default' => null, + 'default' => '', 'example' => 'string', ]) ->addRule('onDelete', [ 'type' => self::TYPE_STRING, 'description' => 'Action to take on related documents when parent document is deleted', - 'default' => null, + 'default' => 'restrict', 'example' => 'restrict|cascade|setNull', ]) ;