diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 9c38b11a72..4896c56ccc 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -351,6 +351,7 @@ function updateAttribute( id: $key, required: $required, default: $default, + filters: [$filter], formatOptions: $options ?? null ); } @@ -1788,10 +1789,18 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/attributes/strin ->param('key', '', new Key(), 'Attribute Key.') ->param('required', null, new Boolean(), 'Is attribute required?') ->param('default', null, new Nullable(new Text(0, 0)), 'Default value for attribute when not provided. Cannot be set when attribute is required.') + ->param('encrypt', null, new Boolean(), 'Encrypt attribute? Encrypting an attribute means that the attribute can not be queried.', true) ->inject('response') ->inject('dbForProject') ->inject('events') - ->action(function (string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, Response $response, Database $dbForProject, Event $events) { + ->action(function (string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, ?bool $encrypt, Response $response, Database $dbForProject, Event $events) { + + $filter = ''; + + if ($encrypt != null) { + $filter = $encrypt ? 'encrypt' : 'decrypt'; + } + $attribute = updateAttribute( databaseId: $databaseId, collectionId: $collectionId, @@ -1799,6 +1808,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/attributes/strin dbForProject: $dbForProject, events: $events, type: Database::VAR_STRING, + filter: empty($filter) ? null : $filter, default: $default, required: $required ); diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index 648a4de800..c4d71d8428 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -695,6 +695,37 @@ class DatabasesCustomServerTest extends Scope $this->assertEquals(200, $document['headers']['status-code']); $this->assertEquals('Jonah', $document['body']['firstName']); $this->assertEquals('Jameson', $document['body']['lastName']); + + /** + * Update Attribute + */ + $updatedFirstname = $this->client->call(Client::METHOD_PATCH, $attributesPath . '/string/' . $firstName['body']['key'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'required' => false, + 'encrypt' => true, + 'default' => '' + ]); + + $this->assertEquals(200, $updatedFirstname['headers']['status-code']); + $this->assertEquals('firstName', $updatedFirstname['body']['key']); + $this->assertEquals('string', $updatedFirstname['body']['type']); + + $updatedLastName = $this->client->call(Client::METHOD_PATCH, $attributesPath . '/string/' . $lastName['body']['key'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), [ + 'required' => false, + 'encrypt' => false, + 'default' => '' + ]); + + $this->assertEquals(200, $updatedLastName['headers']['status-code']); + $this->assertEquals('lastName', $updatedLastName['body']['key']); + $this->assertEquals('string', $updatedLastName['body']['type']); } public function testDeleteAttribute(): array