1
0
Fork 0
mirror of synced 2024-06-02 19:04:49 +12:00

Prevent default values for array attributes

This commit is contained in:
kodumbeats 2021-10-26 16:14:25 -04:00
parent cb6a21f34f
commit c6ee3766b7
2 changed files with 17 additions and 1 deletions

View file

@ -76,6 +76,10 @@ function createAttribute($collectionId, $attribute, $response, $dbForInternal, $
throw new Exception('Cannot set default value for required attribute', 400);
}
if ($array && $default) {
throw new Exception('Cannot set default value for array attributes', 400);
}
try {
$attribute = new Document([
'$id' => $collectionId.'_'.$attributeId,
@ -1591,7 +1595,7 @@ App::post('/v1/database/collections/:collectionId/documents')
$usage
->setParam('database.documents.create', 1)
->setParam('collectionId', $collectionId)
;
;
$audits
->setParam('event', 'database.documents.create')

View file

@ -1338,6 +1338,16 @@ trait DatabaseBase
'max' => 3,
]);
$defaultArray = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/attributes/integer', array_merge([
'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'attributeId' => 'defaultArray',
'required' => false,
'default' => 42,
'array' => true,
]);
$this->assertEquals(201, $email['headers']['status-code']);
$this->assertEquals(201, $ip['headers']['status-code']);
$this->assertEquals(201, $url['headers']['status-code']);
@ -1347,7 +1357,9 @@ trait DatabaseBase
$this->assertEquals(201, $upperBound['headers']['status-code']);
$this->assertEquals(201, $lowerBound['headers']['status-code']);
$this->assertEquals(400, $invalidRange['headers']['status-code']);
$this->assertEquals(400, $defaultArray['headers']['status-code']);
$this->assertEquals('Minimum value must be lesser than maximum value', $invalidRange['body']['message']);
$this->assertEquals('Cannot set default value for array attributes', $defaultArray['body']['message']);
// wait for worker to add attributes
sleep(3);