From ab97b7cc54becbcc48b1d1fdccef57a26ee484c8 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 23 May 2025 15:07:17 +0000 Subject: [PATCH] Merge pull request #9877 from appwrite/revert-9871-feat-sync Revert "Feat sync encrypt updates" --- app/controllers/api/databases.php | 19 +++--------- app/init/database/filters.php | 21 ++++---------- .../Utopia/Response/Model/AttributeString.php | 7 ----- .../e2e/Services/Databases/DatabasesBase.php | 2 +- .../Databases/DatabasesCustomServerTest.php | 29 ++----------------- 5 files changed, 13 insertions(+), 65 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 18b0d87053..277bfae16a 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -1347,11 +1347,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/string ->inject('dbForProject') ->inject('queueForDatabase') ->inject('queueForEvents') - ->inject('plan') - ->action(function (string $databaseId, string $collectionId, string $key, ?int $size, ?bool $required, ?string $default, bool $array, bool $encrypt, Response $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents, array $plan) { - if ($encrypt && !empty($plan) && !($plan['databasesAllowEncrypt'] ?? false)) { - throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Encrypted string attributes are not available on your plan. Please upgrade to create encrypted string attributes.'); - } + ->action(function (string $databaseId, string $collectionId, string $key, ?int $size, ?bool $required, ?string $default, bool $array, bool $encrypt, Response $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents) { // Ensure attribute default is within required size $validator = new Text($size, 0); if (!is_null($default) && !$validator->isValid($default)) { @@ -1372,7 +1368,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/string 'array' => $array, 'filters' => $filters, ]), $response, $dbForProject, $queueForDatabase, $queueForEvents); - $attribute->setAttribute('encrypt', $encrypt); + $response ->setStatusCode(Response::STATUS_CODE_ACCEPTED) ->dynamic($attribute, Response::MODEL_ATTRIBUTE_STRING); @@ -2051,13 +2047,6 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes') throw new Exception(Exception::GENERAL_QUERY_INVALID); } - foreach ($attributes as $attribute) { - if ($attribute->getAttribute('type') === Database::VAR_STRING) { - $filters = $attribute->getAttribute('filters', []); - $attribute->setAttribute('encrypt', in_array('encrypt', $filters)); - } - } - $response->dynamic(new Document([ 'attributes' => $attributes, 'total' => $total, @@ -2122,7 +2111,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes/:key') $type = $attribute->getAttribute('type'); $format = $attribute->getAttribute('format'); $options = $attribute->getAttribute('options', []); - $filters = $attribute->getAttribute('filters', []); + foreach ($options as $key => $option) { $attribute->setAttribute($key, $option); } @@ -2142,7 +2131,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes/:key') }, default => Response::MODEL_ATTRIBUTE, }; - $attribute->setAttribute('encrypt', in_array('encrypt', $filters)); + $response->dynamic($attribute, $model); }); diff --git a/app/init/database/filters.php b/app/init/database/filters.php index c470329706..f110fe1554 100644 --- a/app/init/database/filters.php +++ b/app/init/database/filters.php @@ -77,21 +77,12 @@ Database::addFilter( ]); foreach ($attributes as $attribute) { - $attributeType = $attribute->getAttribute('type'); - - switch ($attributeType) { - case Database::VAR_RELATIONSHIP: - $options = $attribute->getAttribute('options'); - foreach ($options as $key => $value) { - $attribute->setAttribute($key, $value); - } - $attribute->removeAttribute('options'); - break; - - case Database::VAR_STRING: - $filters = $attribute->getAttribute('filters', []); - $attribute->setAttribute('encrypt', in_array('encrypt', $filters)); - break; + if ($attribute->getAttribute('type') === Database::VAR_RELATIONSHIP) { + $options = $attribute->getAttribute('options'); + foreach ($options as $key => $value) { + $attribute->setAttribute($key, $value); + } + $attribute->removeAttribute('options'); } } diff --git a/src/Appwrite/Utopia/Response/Model/AttributeString.php b/src/Appwrite/Utopia/Response/Model/AttributeString.php index fded48fddc..12bb42009d 100644 --- a/src/Appwrite/Utopia/Response/Model/AttributeString.php +++ b/src/Appwrite/Utopia/Response/Model/AttributeString.php @@ -24,13 +24,6 @@ class AttributeString extends Attribute 'required' => false, 'example' => 'default', ]) - ->addRule('encrypt', [ - 'type' => self::TYPE_BOOLEAN, - 'description' => 'Defines whether this attribute is encrypted or not.', - 'default' => false, - 'required' => false, - 'example' => false, - ]) ; } diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 9aed3684de..7c0060ecaa 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -298,7 +298,7 @@ trait DatabasesBase $this->assertEquals($title['body']['type'], 'string'); $this->assertEquals($title['body']['size'], 256); $this->assertEquals($title['body']['required'], true); - $this->assertFalse($title['body']['encrypt']); + $this->assertEquals(202, $description['headers']['status-code']); $this->assertEquals($description['body']['key'], 'description'); $this->assertEquals($description['body']['type'], 'string'); diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index c0d8763aa7..829960b54f 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -695,16 +695,9 @@ class DatabasesCustomServerTest extends Scope 'key' => 'lastName', 'size' => 256, 'required' => true, - 'encrypt' => true + 'encrypt' => true, ]); - $this->assertTrue($lastName['body']['encrypt']); - sleep(1); - $response = $this->client->call(Client::METHOD_GET, $attributesPath . '/lastName', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ])); - $this->assertTrue($response['body']['encrypt']); + /** * Check status of every attribute @@ -748,24 +741,6 @@ class DatabasesCustomServerTest extends Scope $this->assertEquals(200, $document['headers']['status-code']); $this->assertEquals('Jonah', $document['body']['firstName']); $this->assertEquals('Jameson', $document['body']['lastName']); - - - $actors = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $actors['body']['$id'], array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), []); - $attributes = $actors['body']['attributes']; - foreach ($attributes as $attribute) { - $this->assertArrayHasKey('encrypt', $attribute); - if ($attribute['key'] === 'firstName') { - $this->assertFalse($attribute['encrypt']); - } - if ($attribute['key'] === 'lastName') { - $this->assertTrue($attribute['encrypt']); - } - } - } public function testDeleteAttribute(): array