mirror of
https://github.com/appwrite/appwrite
synced 2026-05-22 16:38:32 +00:00
Merge pull request #9871 from appwrite/feat-sync
Feat sync encrypt updates
This commit is contained in:
commit
0b0a1c20e9
5 changed files with 65 additions and 13 deletions
|
|
@ -1347,7 +1347,11 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/string
|
|||
->inject('dbForProject')
|
||||
->inject('queueForDatabase')
|
||||
->inject('queueForEvents')
|
||||
->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) {
|
||||
->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.');
|
||||
}
|
||||
// Ensure attribute default is within required size
|
||||
$validator = new Text($size, 0);
|
||||
if (!is_null($default) && !$validator->isValid($default)) {
|
||||
|
|
@ -1368,7 +1372,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 +2051,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 +2122,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 +2142,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);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -695,9 +695,16 @@ 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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue