From e586afceb74eca90d800323b10056b97db5a18c6 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 23 May 2025 14:11:57 +0530 Subject: [PATCH] updates --- app/controllers/api/databases.php | 1 - app/init/database/filters.php | 24 +++++++++++-------- .../Databases/DatabasesCustomServerTest.php | 8 ++----- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 5cc1369f00..0d4e535b1b 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -2053,7 +2053,6 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes') } - foreach ($attributes as $attribute) { if ($attribute->getAttribute('type') === Database::VAR_STRING) { $filters = $attribute->getAttribute('filters', []); diff --git a/app/init/database/filters.php b/app/init/database/filters.php index 44fd748758..c470329706 100644 --- a/app/init/database/filters.php +++ b/app/init/database/filters.php @@ -78,16 +78,20 @@ Database::addFilter( foreach ($attributes as $attribute) { $attributeType = $attribute->getAttribute('type'); - if ($attributeType === Database::VAR_RELATIONSHIP) { - $options = $attribute->getAttribute('options'); - foreach ($options as $key => $value) { - $attribute->setAttribute($key, $value); - } - $attribute->removeAttribute('options'); - } - if ($attributeType === Database::VAR_STRING) { - $filters = $attribute->getAttribute('filters', []); - $attribute->setAttribute('encrypt', in_array('encrypt', $filters)); + + 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; } } diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index 3d5ba61585..c0d8763aa7 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -756,19 +756,15 @@ class DatabasesCustomServerTest extends Scope 'x-appwrite-key' => $this->getProject()['apiKey'] ]), []); $attributes = $actors['body']['attributes']; - $firstNameAttribute = null; - $lastNameAttribute = null; foreach ($attributes as $attribute) { $this->assertArrayHasKey('encrypt', $attribute); if ($attribute['key'] === 'firstName') { - $firstNameAttribute = $attribute['encrypt']; + $this->assertFalse($attribute['encrypt']); } if ($attribute['key'] === 'lastName') { - $lastNameAttribute = $attribute['encrypt']; + $this->assertTrue($attribute['encrypt']); } } - $this->assertTrue($lastNameAttribute); - $this->assertFalse($firstNameAttribute); }