mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 00:49:02 +00:00
Merge pull request #10364 from appwrite/upsert-documnet-no-change-1.8
Upsert document no change
This commit is contained in:
commit
d826e5c705
3 changed files with 89 additions and 0 deletions
|
|
@ -97,6 +97,10 @@ class Upsert extends Action
|
|||
throw new Exception($this->getMissingPayloadException());
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
|
|
@ -265,7 +269,13 @@ class Upsert extends Action
|
|||
}
|
||||
|
||||
$collectionsCache = [];
|
||||
|
||||
if (empty($upserted[0])) {
|
||||
$upserted[0] = $dbForProject->getDocument('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $documentId);
|
||||
}
|
||||
|
||||
$document = $upserted[0];
|
||||
|
||||
$this->processDocument(
|
||||
database: $database,
|
||||
collection: $collection,
|
||||
|
|
|
|||
|
|
@ -1728,6 +1728,35 @@ trait DatabasesBase
|
|||
|
||||
$this->assertEquals('Thor: Ragnarok', $document['body']['title']);
|
||||
|
||||
/**
|
||||
* Resubmit same document, nothing to update
|
||||
*/
|
||||
$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: Ragnarok',
|
||||
'releaseYear' => 2000,
|
||||
'integers' => [],
|
||||
'birthDay' => null,
|
||||
'duration' => null,
|
||||
'starringActors' => [],
|
||||
'actors' => [],
|
||||
'tagline' => '',
|
||||
'description' => '',
|
||||
],
|
||||
'permissions' => [
|
||||
Permission::read(Role::users()),
|
||||
Permission::update(Role::users()),
|
||||
Permission::delete(Role::users()),
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $document['headers']['status-code']);
|
||||
$this->assertEquals('Thor: Ragnarok', $document['body']['title']);
|
||||
$this->assertCount(3, $document['body']['$permissions']);
|
||||
|
||||
$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'],
|
||||
|
|
|
|||
|
|
@ -1693,6 +1693,56 @@ trait DatabasesBase
|
|||
|
||||
$this->assertEquals('Thor: Ragnarok', $row['body']['title']);
|
||||
|
||||
/**
|
||||
* Resubmit same document, nothing to update
|
||||
*/
|
||||
$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',
|
||||
'releaseYear' => 2000,
|
||||
'integers' => [],
|
||||
'birthDay' => null,
|
||||
'duration' => null,
|
||||
'starringActors' => [],
|
||||
'actors' => [],
|
||||
'tagline' => '',
|
||||
'description' => '',
|
||||
],
|
||||
'permissions' => [
|
||||
Permission::read(Role::users()),
|
||||
Permission::update(Role::users()),
|
||||
Permission::delete(Role::users()),
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $row['headers']['status-code']);
|
||||
$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'],
|
||||
|
|
|
|||
Loading…
Reference in a new issue