Restrict array list

This commit is contained in:
fogelito
2025-08-24 18:08:12 +03:00
parent ba79dda788
commit 959db2ea02
3 changed files with 26 additions and 43 deletions
@@ -97,12 +97,9 @@ class Upsert extends Action
throw new Exception($this->getMissingPayloadException());
}
// if (!empty($data) && \array_is_list($data)) {
// throw new Exception('shmuel');
// }
var_dump(array_is_list($data));
var_dump($data);
if (\array_is_list($data) && \count($data) > 1) { // Allow 1 associated array
throw new Exception($this->getMissingPayloadException());
}
$isAPIKey = Auth::isAppUser(Authorization::getRoles());
$isPrivilegedUser = Auth::isPrivilegedUser(Authorization::getRoles());
@@ -1735,7 +1735,7 @@ trait DatabasesBase
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'data' => [
'data' => [[
'title' => 'Thor: Ragnarok',
'releaseYear' => 2000,
'integers' => [],
@@ -1745,7 +1745,7 @@ trait DatabasesBase
'actors' => [],
'tagline' => '',
'description' => '',
],
]],
'permissions' => [
Permission::read(Role::users()),
Permission::update(Role::users()),
@@ -1753,41 +1753,6 @@ trait DatabasesBase
],
]);
$document = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents/' . $documentId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'data' => [
[
'title' => 'Thor: Ragnarok1',
'releaseYear' => 2000,
'integers' => [],
'birthDay' => null,
'duration' => null,
'starringActors' => [],
'actors' => [],
'tagline' => '',
'description' => '',
],
[
'title' => 'Thor: Ragnarok2',
'releaseYear' => 2000,
'integers' => [],
'birthDay' => null,
'duration' => null,
'starringActors' => [],
'actors' => [],
'tagline' => '',
'description' => '',
]
],
'permissions' => [
Permission::read(Role::users()),
Permission::update(Role::users()),
Permission::delete(Role::users()),
],
]);
var_dump($document);
$this->assertEquals(200, $document['headers']['status-code']);
$this->assertEquals('Thor: Ragnarok', $document['body']['title']);
$this->assertCount(3, $document['body']['$permissions']);
@@ -1722,6 +1722,27 @@ trait DatabasesBase
$this->assertEquals('Thor: Ragnarok', $row['body']['title']);
$this->assertCount(3, $row['body']['$permissions']);
/**
* Do not allow array list
*/
$row = $this->client->call(Client::METHOD_PUT, '/tablesdb/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/' . $rowId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'data' => [
[
'title' => 'Thor: Ragnarok 1',
],
[
'title' => 'Thor: Ragnarok 2',
]
],
'permissions' => [
Permission::read(Role::users()),
],
]);
$this->assertEquals(400, $row['headers']['status-code']);
$row = $this->client->call(Client::METHOD_PUT, '/tablesdb/' . $databaseId . '/tables/' . $data['moviesId'] . '/rows/' . $rowId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],