From d45464c6c8e564a76e80b1f814d5bac79cb2eaa8 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 30 Sep 2022 11:27:19 +0200 Subject: [PATCH 1/2] fix: boolean attribute default value --- app/controllers/api/databases.php | 4 +- composer.lock | 12 ++--- .../e2e/Services/Databases/DatabasesBase.php | 48 +++++++++++++++++++ 3 files changed, 56 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index a66df37124..5278abae3e 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -89,11 +89,11 @@ function createAttribute(string $databaseId, string $collectionId, Document $att } // Must throw here since dbForProject->createAttribute is performed by db worker - if ($required && $default) { + if ($required && isset($default)) { throw new Exception(Exception::ATTRIBUTE_DEFAULT_UNSUPPORTED, 'Cannot set default value for required attribute'); } - if ($array && $default) { + if ($array && isset($default)) { throw new Exception(Exception::ATTRIBUTE_DEFAULT_UNSUPPORTED, 'Cannot set default value for array attributes'); } diff --git a/composer.lock b/composer.lock index 9ec0ea3197..7d676b49d5 100644 --- a/composer.lock +++ b/composer.lock @@ -5283,16 +5283,16 @@ }, { "name": "twig/twig", - "version": "v3.4.2", + "version": "v3.4.3", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "e07cdd3d430cd7e453c31b36eb5ad6c0c5e43077" + "reference": "c38fd6b0b7f370c198db91ffd02e23b517426b58" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/e07cdd3d430cd7e453c31b36eb5ad6c0c5e43077", - "reference": "e07cdd3d430cd7e453c31b36eb5ad6c0c5e43077", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/c38fd6b0b7f370c198db91ffd02e23b517426b58", + "reference": "c38fd6b0b7f370c198db91ffd02e23b517426b58", "shasum": "" }, "require": { @@ -5343,7 +5343,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.4.2" + "source": "https://github.com/twigphp/Twig/tree/v3.4.3" }, "funding": [ { @@ -5355,7 +5355,7 @@ "type": "tidelift" } ], - "time": "2022-08-12T06:47:24+00:00" + "time": "2022-09-28T08:42:51+00:00" } ], "aliases": [], diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index fc3cf161e8..a183325039 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -2968,4 +2968,52 @@ trait DatabasesBase return []; } + + /** + * @depends testCreateDatabase + */ + public function testAttributeBooleanDefault(array $data): void + { + $databaseId = $data['databaseId']; + + /** + * Test for SUCCESS + */ + $collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Boolean' + ]); + + $this->assertEquals(201, $collection['headers']['status-code']); + + $collectionId = $collection['body']['$id']; + + $true = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/boolean', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'true', + 'required' => false, + 'default' => true + ]); + + $this->assertEquals(202, $true['headers']['status-code']); + + $false = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/boolean', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'false', + 'required' => false, + 'default' => false + ]); + + $this->assertEquals(202, $false['headers']['status-code']); + } } From b79fe964b8fcb01bfc1d9a9bd81905161252fed5 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 30 Sep 2022 11:37:38 +0200 Subject: [PATCH 2/2] chore: add changelog --- CHANGES.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 68ca4abd17..8a7764c31b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,10 @@ +# Version 1.0.2 +## Bugs +- Fixed default value for creating Boolean Attribute [#4040](https://github.com/appwrite/appwrite/pull/404) + # Version 1.0.1 ## Bugs -- Fixed migration for abuse by migrating the `time` attribute [3839](https://github.com/appwrite/appwrite/pull/3839) +- Fixed migration for abuse by migrating the `time` attribute [#3839](https://github.com/appwrite/appwrite/pull/3839) # Version 1.0.0 ## BREAKING CHANGES