chore: add encrypt param on update string attr + unit tests
This commit is contained in:
parent
96f1284cbf
commit
f71fdfb0b9
2 changed files with 42 additions and 1 deletions
|
@ -351,6 +351,7 @@ function updateAttribute(
|
||||||
id: $key,
|
id: $key,
|
||||||
required: $required,
|
required: $required,
|
||||||
default: $default,
|
default: $default,
|
||||||
|
filters: [$filter],
|
||||||
formatOptions: $options ?? null
|
formatOptions: $options ?? null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1788,10 +1789,18 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/attributes/strin
|
||||||
->param('key', '', new Key(), 'Attribute Key.')
|
->param('key', '', new Key(), 'Attribute Key.')
|
||||||
->param('required', null, new Boolean(), 'Is attribute required?')
|
->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('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('response')
|
||||||
->inject('dbForProject')
|
->inject('dbForProject')
|
||||||
->inject('events')
|
->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(
|
$attribute = updateAttribute(
|
||||||
databaseId: $databaseId,
|
databaseId: $databaseId,
|
||||||
collectionId: $collectionId,
|
collectionId: $collectionId,
|
||||||
|
@ -1799,6 +1808,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/attributes/strin
|
||||||
dbForProject: $dbForProject,
|
dbForProject: $dbForProject,
|
||||||
events: $events,
|
events: $events,
|
||||||
type: Database::VAR_STRING,
|
type: Database::VAR_STRING,
|
||||||
|
filter: empty($filter) ? null : $filter,
|
||||||
default: $default,
|
default: $default,
|
||||||
required: $required
|
required: $required
|
||||||
);
|
);
|
||||||
|
|
|
@ -695,6 +695,37 @@ class DatabasesCustomServerTest extends Scope
|
||||||
$this->assertEquals(200, $document['headers']['status-code']);
|
$this->assertEquals(200, $document['headers']['status-code']);
|
||||||
$this->assertEquals('Jonah', $document['body']['firstName']);
|
$this->assertEquals('Jonah', $document['body']['firstName']);
|
||||||
$this->assertEquals('Jameson', $document['body']['lastName']);
|
$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
|
public function testDeleteAttribute(): array
|
||||||
|
|
Loading…
Reference in a new issue