Merge pull request #9868 from ArnabChatterjee20k/dat-532

added encrypt property in the attribute string response model
This commit is contained in:
Jake Barnby
2025-05-23 09:03:42 +00:00
parent 02de47f1dc
commit 1a2a725cb0
5 changed files with 59 additions and 11 deletions
+10 -3
View File
@@ -1368,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);
@@ -2047,6 +2047,13 @@ 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,
@@ -2111,7 +2118,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);
}
@@ -2131,7 +2138,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);
});
+15 -6
View File
@@ -77,12 +77,21 @@ Database::addFilter(
]);
foreach ($attributes as $attribute) {
if ($attribute->getAttribute('type') === Database::VAR_RELATIONSHIP) {
$options = $attribute->getAttribute('options');
foreach ($options as $key => $value) {
$attribute->setAttribute($key, $value);
}
$attribute->removeAttribute('options');
$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;
}
}
@@ -24,6 +24,13 @@ 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,
])
;
}
@@ -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');
@@ -697,7 +697,14 @@ class DatabasesCustomServerTest extends Scope
'required' => 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
@@ -741,6 +748,24 @@ 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