From b295a66f8f46b621aa9e70bdf443d9c57c3c93a0 Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 28 Dec 2023 12:38:58 +0200 Subject: [PATCH 1/4] fix relation --- composer.lock | 54 ++++++++++++++-------------- src/Database/Validator/Structure.php | 6 ++-- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/composer.lock b/composer.lock index e12850141..1a6b42b8a 100644 --- a/composer.lock +++ b/composer.lock @@ -268,16 +268,16 @@ }, { "name": "utopia-php/framework", - "version": "0.31.1", + "version": "0.32.0", "source": { "type": "git", "url": "https://github.com/utopia-php/framework.git", - "reference": "e50d2d16f4bc31319043f3f6d3dbea36c6fd6b68" + "reference": "ad6f7e6d6b38cf5bed4e3af9a1394c59d4bb9225" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/framework/zipball/e50d2d16f4bc31319043f3f6d3dbea36c6fd6b68", - "reference": "e50d2d16f4bc31319043f3f6d3dbea36c6fd6b68", + "url": "https://api.github.com/repos/utopia-php/framework/zipball/ad6f7e6d6b38cf5bed4e3af9a1394c59d4bb9225", + "reference": "ad6f7e6d6b38cf5bed4e3af9a1394c59d4bb9225", "shasum": "" }, "require": { @@ -307,9 +307,9 @@ ], "support": { "issues": "https://github.com/utopia-php/framework/issues", - "source": "https://github.com/utopia-php/framework/tree/0.31.1" + "source": "https://github.com/utopia-php/framework/tree/0.32.0" }, - "time": "2023-12-08T18:47:29+00:00" + "time": "2023-12-26T14:18:36+00:00" }, { "name": "utopia-php/mongo", @@ -901,23 +901,23 @@ }, { "name": "phpunit/php-code-coverage", - "version": "9.2.29", + "version": "9.2.30", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "6a3a87ac2bbe33b25042753df8195ba4aa534c76" + "reference": "ca2bd87d2f9215904682a9cb9bb37dda98e76089" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/6a3a87ac2bbe33b25042753df8195ba4aa534c76", - "reference": "6a3a87ac2bbe33b25042753df8195ba4aa534c76", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ca2bd87d2f9215904682a9cb9bb37dda98e76089", + "reference": "ca2bd87d2f9215904682a9cb9bb37dda98e76089", "shasum": "" }, "require": { "ext-dom": "*", "ext-libxml": "*", "ext-xmlwriter": "*", - "nikic/php-parser": "^4.15", + "nikic/php-parser": "^4.18 || ^5.0", "php": ">=7.3", "phpunit/php-file-iterator": "^3.0.3", "phpunit/php-text-template": "^2.0.2", @@ -967,7 +967,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.29" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.30" }, "funding": [ { @@ -975,7 +975,7 @@ "type": "github" } ], - "time": "2023-09-19T04:57:46+00:00" + "time": "2023-12-22T06:47:57+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1663,20 +1663,20 @@ }, { "name": "sebastian/complexity", - "version": "2.0.2", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/complexity.git", - "reference": "739b35e53379900cc9ac327b2147867b8b6efd88" + "reference": "25f207c40d62b8b7aa32f5ab026c53561964053a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/739b35e53379900cc9ac327b2147867b8b6efd88", - "reference": "739b35e53379900cc9ac327b2147867b8b6efd88", + "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/25f207c40d62b8b7aa32f5ab026c53561964053a", + "reference": "25f207c40d62b8b7aa32f5ab026c53561964053a", "shasum": "" }, "require": { - "nikic/php-parser": "^4.7", + "nikic/php-parser": "^4.18 || ^5.0", "php": ">=7.3" }, "require-dev": { @@ -1708,7 +1708,7 @@ "homepage": "https://github.com/sebastianbergmann/complexity", "support": { "issues": "https://github.com/sebastianbergmann/complexity/issues", - "source": "https://github.com/sebastianbergmann/complexity/tree/2.0.2" + "source": "https://github.com/sebastianbergmann/complexity/tree/2.0.3" }, "funding": [ { @@ -1716,7 +1716,7 @@ "type": "github" } ], - "time": "2020-10-26T15:52:27+00:00" + "time": "2023-12-22T06:19:30+00:00" }, { "name": "sebastian/diff", @@ -1990,20 +1990,20 @@ }, { "name": "sebastian/lines-of-code", - "version": "1.0.3", + "version": "1.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/lines-of-code.git", - "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc" + "reference": "e1e4a170560925c26d424b6a03aed157e7dcc5c5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/c1c2e997aa3146983ed888ad08b15470a2e22ecc", - "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/e1e4a170560925c26d424b6a03aed157e7dcc5c5", + "reference": "e1e4a170560925c26d424b6a03aed157e7dcc5c5", "shasum": "" }, "require": { - "nikic/php-parser": "^4.6", + "nikic/php-parser": "^4.18 || ^5.0", "php": ">=7.3" }, "require-dev": { @@ -2035,7 +2035,7 @@ "homepage": "https://github.com/sebastianbergmann/lines-of-code", "support": { "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", - "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.3" + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.4" }, "funding": [ { @@ -2043,7 +2043,7 @@ "type": "github" } ], - "time": "2020-11-28T06:42:11+00:00" + "time": "2023-12-22T06:20:34+00:00" }, { "name": "sebastian/object-enumerator", diff --git a/src/Database/Validator/Structure.php b/src/Database/Validator/Structure.php index 3d7d2ade7..474e11a3c 100644 --- a/src/Database/Validator/Structure.php +++ b/src/Database/Validator/Structure.php @@ -254,6 +254,10 @@ public function isValid($document): bool continue; } + if($type === Database::VAR_RELATIONSHIP){ + continue; + } + switch ($type) { case Database::VAR_STRING: $size = $attribute['size'] ?? 0; @@ -276,8 +280,6 @@ public function isValid($document): bool $validator = new DatetimeValidator(); break; - case Database::VAR_RELATIONSHIP: - return true; default: $this->message = 'Unknown attribute type "'.$type.'"'; return false; From 05ee5b6034d5002152da4a426b89f87a2fa77f47 Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 28 Dec 2023 12:43:27 +0200 Subject: [PATCH 2/4] lint --- src/Database/Validator/Structure.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Database/Validator/Structure.php b/src/Database/Validator/Structure.php index 474e11a3c..db57ce8d8 100644 --- a/src/Database/Validator/Structure.php +++ b/src/Database/Validator/Structure.php @@ -254,7 +254,7 @@ public function isValid($document): bool continue; } - if($type === Database::VAR_RELATIONSHIP){ + if($type === Database::VAR_RELATIONSHIP) { continue; } From a42aba51379b0fad41928abbec8abe8e8fde73ad Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 9 Jan 2024 16:12:15 +0200 Subject: [PATCH 3/4] add test --- composer.lock | 43 +++++++++++++++++--------------------- tests/e2e/Adapter/Base.php | 30 ++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 24 deletions(-) diff --git a/composer.lock b/composer.lock index 1a6b42b8a..b3e4b460f 100644 --- a/composer.lock +++ b/composer.lock @@ -268,16 +268,16 @@ }, { "name": "utopia-php/framework", - "version": "0.32.0", + "version": "0.33.0", "source": { "type": "git", - "url": "https://github.com/utopia-php/framework.git", - "reference": "ad6f7e6d6b38cf5bed4e3af9a1394c59d4bb9225" + "url": "https://github.com/utopia-php/http.git", + "reference": "e3ff6b933082d57b48e7c4267bb605c0bf2250fd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/framework/zipball/ad6f7e6d6b38cf5bed4e3af9a1394c59d4bb9225", - "reference": "ad6f7e6d6b38cf5bed4e3af9a1394c59d4bb9225", + "url": "https://api.github.com/repos/utopia-php/http/zipball/e3ff6b933082d57b48e7c4267bb605c0bf2250fd", + "reference": "e3ff6b933082d57b48e7c4267bb605c0bf2250fd", "shasum": "" }, "require": { @@ -306,10 +306,10 @@ "upf" ], "support": { - "issues": "https://github.com/utopia-php/framework/issues", - "source": "https://github.com/utopia-php/framework/tree/0.32.0" + "issues": "https://github.com/utopia-php/http/issues", + "source": "https://github.com/utopia-php/http/tree/0.33.0" }, - "time": "2023-12-26T14:18:36+00:00" + "time": "2024-01-08T13:30:27+00:00" }, { "name": "utopia-php/mongo", @@ -445,16 +445,16 @@ }, { "name": "fakerphp/faker", - "version": "v1.23.0", + "version": "v1.23.1", "source": { "type": "git", "url": "https://github.com/FakerPHP/Faker.git", - "reference": "e3daa170d00fde61ea7719ef47bb09bb8f1d9b01" + "reference": "bfb4fe148adbf78eff521199619b93a52ae3554b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FakerPHP/Faker/zipball/e3daa170d00fde61ea7719ef47bb09bb8f1d9b01", - "reference": "e3daa170d00fde61ea7719ef47bb09bb8f1d9b01", + "url": "https://api.github.com/repos/FakerPHP/Faker/zipball/bfb4fe148adbf78eff521199619b93a52ae3554b", + "reference": "bfb4fe148adbf78eff521199619b93a52ae3554b", "shasum": "" }, "require": { @@ -480,11 +480,6 @@ "ext-mbstring": "Required for multibyte Unicode string functionality." }, "type": "library", - "extra": { - "branch-alias": { - "dev-main": "v1.21-dev" - } - }, "autoload": { "psr-4": { "Faker\\": "src/Faker/" @@ -507,9 +502,9 @@ ], "support": { "issues": "https://github.com/FakerPHP/Faker/issues", - "source": "https://github.com/FakerPHP/Faker/tree/v1.23.0" + "source": "https://github.com/FakerPHP/Faker/tree/v1.23.1" }, - "time": "2023-06-12T08:44:38+00:00" + "time": "2024-01-02T13:46:09+00:00" }, { "name": "laravel/pint", @@ -839,16 +834,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.50", + "version": "1.10.55", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "06a98513ac72c03e8366b5a0cb00750b487032e4" + "reference": "9a88f9d18ddf4cf54c922fbeac16c4cb164c5949" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/06a98513ac72c03e8366b5a0cb00750b487032e4", - "reference": "06a98513ac72c03e8366b5a0cb00750b487032e4", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/9a88f9d18ddf4cf54c922fbeac16c4cb164c5949", + "reference": "9a88f9d18ddf4cf54c922fbeac16c4cb164c5949", "shasum": "" }, "require": { @@ -897,7 +892,7 @@ "type": "tidelift" } ], - "time": "2023-12-13T10:59:42+00:00" + "time": "2024-01-08T12:32:40+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/tests/e2e/Adapter/Base.php b/tests/e2e/Adapter/Base.php index 6eb5f4f37..8e1844be4 100644 --- a/tests/e2e/Adapter/Base.php +++ b/tests/e2e/Adapter/Base.php @@ -3646,6 +3646,36 @@ public function testNoChangeUpdateDocumentWithoutPermission(Document $document): return $document; } + public function testStructureValidationAfterRelationsAttribute(): void + { + if (!static::getDatabase()->getAdapter()->getSupportForRelationships()) { + $this->expectNotToPerformAssertions(); + return; + } + + static::getDatabase()->createCollection("structure_1", [], [], [Permission::create(Role::any())]); + static::getDatabase()->createCollection("structure_2", [], [], [Permission::create(Role::any())]); + + static::getDatabase()->createRelationship( + collection: "structure_1", + relatedCollection: "structure_2", + type: Database::RELATION_ONE_TO_ONE, + ); + + try { + static::getDatabase()->createDocument('structure_1', new Document([ + '$permissions' => [ + Permission::read(Role::any()), + ], + 'structure_2' => '100', + 'name' => 'Frozen', // Unknown attribute 'name' after relation attribute + ])); + $this->fail('Failed to throw exception'); + } catch(Exception $e) { + $this->assertInstanceOf(StructureException::class, $e); + } + } + public function testNoChangeUpdateDocumentWithRelationWithoutPermission(): void { if (!static::getDatabase()->getAdapter()->getSupportForRelationships()) { From c2ecd1693485232f2b88b9762f7e86ac9792213c Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 9 Jan 2024 16:18:08 +0200 Subject: [PATCH 4/4] composer.lock --- composer.lock | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/composer.lock b/composer.lock index a37087417..c021e464e 100644 --- a/composer.lock +++ b/composer.lock @@ -269,16 +269,16 @@ }, { "name": "utopia-php/framework", - "version": "0.32.0", + "version": "0.33.0", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "ad6f7e6d6b38cf5bed4e3af9a1394c59d4bb9225" + "reference": "e3ff6b933082d57b48e7c4267bb605c0bf2250fd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/ad6f7e6d6b38cf5bed4e3af9a1394c59d4bb9225", - "reference": "ad6f7e6d6b38cf5bed4e3af9a1394c59d4bb9225", + "url": "https://api.github.com/repos/utopia-php/http/zipball/e3ff6b933082d57b48e7c4267bb605c0bf2250fd", + "reference": "e3ff6b933082d57b48e7c4267bb605c0bf2250fd", "shasum": "" }, "require": { @@ -308,9 +308,9 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/0.32.0" + "source": "https://github.com/utopia-php/http/tree/0.33.0" }, - "time": "2023-12-26T14:18:36+00:00" + "time": "2024-01-08T13:30:27+00:00" }, { "name": "utopia-php/mongo", @@ -835,16 +835,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.54", + "version": "1.10.55", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "3e25f279dada0adc14ffd7bad09af2e2fc3523bb" + "reference": "9a88f9d18ddf4cf54c922fbeac16c4cb164c5949" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/3e25f279dada0adc14ffd7bad09af2e2fc3523bb", - "reference": "3e25f279dada0adc14ffd7bad09af2e2fc3523bb", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/9a88f9d18ddf4cf54c922fbeac16c4cb164c5949", + "reference": "9a88f9d18ddf4cf54c922fbeac16c4cb164c5949", "shasum": "" }, "require": { @@ -893,7 +893,7 @@ "type": "tidelift" } ], - "time": "2024-01-05T15:50:47+00:00" + "time": "2024-01-08T12:32:40+00:00" }, { "name": "phpunit/php-code-coverage", @@ -2604,5 +2604,5 @@ "php": ">=8.0" }, "platform-dev": [], - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.6.0" }