Address Comments, fix permission bug

This commit is contained in:
Bradley Schofield
2024-11-13 13:41:18 +09:00
parent 92c93357cf
commit dd6bd745df
4 changed files with 116 additions and 58 deletions
+3
View File
@@ -3769,6 +3769,9 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents')
}
}
if (!\is_null($permissions)) {
$data['$permissions'] = $permissions;
}
$partialDocument = new Document($data);
try {
Generated
+43 -43
View File
@@ -2222,16 +2222,16 @@
},
{
"name": "utopia-php/migration",
"version": "0.6.11",
"version": "0.6.12",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/migration.git",
"reference": "4d167914d3f7fa1fe816b2b2c6f221e70166bfd7"
"reference": "9a8c905af4cece5c5ec9542a5b534befce067260"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/migration/zipball/4d167914d3f7fa1fe816b2b2c6f221e70166bfd7",
"reference": "4d167914d3f7fa1fe816b2b2c6f221e70166bfd7",
"url": "https://api.github.com/repos/utopia-php/migration/zipball/9a8c905af4cece5c5ec9542a5b534befce067260",
"reference": "9a8c905af4cece5c5ec9542a5b534befce067260",
"shasum": ""
},
"require": {
@@ -2272,9 +2272,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/migration/issues",
"source": "https://github.com/utopia-php/migration/tree/0.6.11"
"source": "https://github.com/utopia-php/migration/tree/0.6.12"
},
"time": "2024-10-31T06:19:57+00:00"
"time": "2024-11-12T00:31:53+00:00"
},
{
"name": "utopia-php/mongo",
@@ -2542,16 +2542,16 @@
},
{
"name": "utopia-php/queue",
"version": "0.7.1",
"version": "0.7.2",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/queue.git",
"reference": "94c240d9f6383829807ce7b2d737f04b159fd3e8"
"reference": "40fdd9799d0a11dd33fca06f8223032a47dce2f6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/queue/zipball/94c240d9f6383829807ce7b2d737f04b159fd3e8",
"reference": "94c240d9f6383829807ce7b2d737f04b159fd3e8",
"url": "https://api.github.com/repos/utopia-php/queue/zipball/40fdd9799d0a11dd33fca06f8223032a47dce2f6",
"reference": "40fdd9799d0a11dd33fca06f8223032a47dce2f6",
"shasum": ""
},
"require": {
@@ -2597,9 +2597,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/queue/issues",
"source": "https://github.com/utopia-php/queue/tree/0.7.1"
"source": "https://github.com/utopia-php/queue/tree/0.7.2"
},
"time": "2024-11-05T17:00:38+00:00"
"time": "2024-11-11T10:04:02+00:00"
},
{
"name": "utopia-php/registry",
@@ -2817,16 +2817,16 @@
},
{
"name": "utopia-php/vcs",
"version": "0.8.3",
"version": "0.8.5",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/vcs.git",
"reference": "a032ed0611a8f4467aeaa9484f73223074457337"
"reference": "7622330628d53844a3873ca873338150756bab82"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/vcs/zipball/a032ed0611a8f4467aeaa9484f73223074457337",
"reference": "a032ed0611a8f4467aeaa9484f73223074457337",
"url": "https://api.github.com/repos/utopia-php/vcs/zipball/7622330628d53844a3873ca873338150756bab82",
"reference": "7622330628d53844a3873ca873338150756bab82",
"shasum": ""
},
"require": {
@@ -2860,9 +2860,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/vcs/issues",
"source": "https://github.com/utopia-php/vcs/tree/0.8.3"
"source": "https://github.com/utopia-php/vcs/tree/0.8.5"
},
"time": "2024-11-05T17:10:09+00:00"
"time": "2024-11-11T18:33:10+00:00"
},
{
"name": "utopia-php/websocket",
@@ -4051,16 +4051,16 @@
},
{
"name": "phpdocumentor/reflection-docblock",
"version": "5.5.1",
"version": "5.6.0",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
"reference": "0c70d2c566e899666f367ab7b80986beb3581e6f"
"reference": "f3558a4c23426d12bffeaab463f8a8d8b681193c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/0c70d2c566e899666f367ab7b80986beb3581e6f",
"reference": "0c70d2c566e899666f367ab7b80986beb3581e6f",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/f3558a4c23426d12bffeaab463f8a8d8b681193c",
"reference": "f3558a4c23426d12bffeaab463f8a8d8b681193c",
"shasum": ""
},
"require": {
@@ -4069,7 +4069,7 @@
"php": "^7.4 || ^8.0",
"phpdocumentor/reflection-common": "^2.2",
"phpdocumentor/type-resolver": "^1.7",
"phpstan/phpdoc-parser": "^1.7",
"phpstan/phpdoc-parser": "^1.7|^2.0",
"webmozart/assert": "^1.9.1"
},
"require-dev": {
@@ -4109,9 +4109,9 @@
"description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
"support": {
"issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues",
"source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.5.1"
"source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.6.0"
},
"time": "2024-11-06T11:58:54+00:00"
"time": "2024-11-12T11:25:25+00:00"
},
{
"name": "phpdocumentor/type-resolver",
@@ -4242,30 +4242,30 @@
},
{
"name": "phpstan/phpdoc-parser",
"version": "1.33.0",
"version": "2.0.0",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpdoc-parser.git",
"reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140"
"reference": "c00d78fb6b29658347f9d37ebe104bffadf36299"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/82a311fd3690fb2bf7b64d5c98f912b3dd746140",
"reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/c00d78fb6b29658347f9d37ebe104bffadf36299",
"reference": "c00d78fb6b29658347f9d37ebe104bffadf36299",
"shasum": ""
},
"require": {
"php": "^7.2 || ^8.0"
"php": "^7.4 || ^8.0"
},
"require-dev": {
"doctrine/annotations": "^2.0",
"nikic/php-parser": "^4.15",
"nikic/php-parser": "^5.3.0",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^1.5",
"phpstan/phpstan-phpunit": "^1.1",
"phpstan/phpstan-strict-rules": "^1.0",
"phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^9.6",
"symfony/process": "^5.2"
},
"type": "library",
@@ -4283,9 +4283,9 @@
"description": "PHPDoc parser with support for nullable, intersection and generic types",
"support": {
"issues": "https://github.com/phpstan/phpdoc-parser/issues",
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.33.0"
"source": "https://github.com/phpstan/phpdoc-parser/tree/2.0.0"
},
"time": "2024-10-13T11:25:22+00:00"
"time": "2024-10-13T11:29:49+00:00"
},
{
"name": "phpunit/php-code-coverage",
@@ -6923,16 +6923,16 @@
},
{
"name": "twig/twig",
"version": "v3.14.1",
"version": "v3.14.2",
"source": {
"type": "git",
"url": "https://github.com/twigphp/Twig.git",
"reference": "f405356d20fb43603bcadc8b09bfb676cb04a379"
"reference": "0b6f9d8370bb3b7f1ce5313ed8feb0fafd6e399a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/f405356d20fb43603bcadc8b09bfb676cb04a379",
"reference": "f405356d20fb43603bcadc8b09bfb676cb04a379",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/0b6f9d8370bb3b7f1ce5313ed8feb0fafd6e399a",
"reference": "0b6f9d8370bb3b7f1ce5313ed8feb0fafd6e399a",
"shasum": ""
},
"require": {
@@ -6986,7 +6986,7 @@
],
"support": {
"issues": "https://github.com/twigphp/Twig/issues",
"source": "https://github.com/twigphp/Twig/tree/v3.14.1"
"source": "https://github.com/twigphp/Twig/tree/v3.14.2"
},
"funding": [
{
@@ -6998,7 +6998,7 @@
"type": "tidelift"
}
],
"time": "2024-11-06T18:17:38+00:00"
"time": "2024-11-07T12:36:22+00:00"
},
{
"name": "webmozart/glob",
+66 -11
View File
@@ -4901,17 +4901,15 @@ trait DatabasesBase
$this->assertEquals(200, $documents['headers']['status-code']);
$this->assertEquals(10, $documents['body']['total']);
if ($this->getSide() === 'client') {
foreach ($documents['body']['documents'] as $document) {
$this->assertEquals([
Permission::read(Role::user($this->getUser()['$id'])),
Permission::update(Role::user($this->getUser()['$id'])),
Permission::delete(Role::user($this->getUser()['$id'])),
], $document['$permissions']);
}
foreach ($documents['body']['documents'] as $document) {
$this->assertEquals([
Permission::read(Role::user($this->getUser()['$id'])),
Permission::update(Role::user($this->getUser()['$id'])),
Permission::delete(Role::user($this->getUser()['$id'])),
], $document['$permissions']);
}
// TEST: Update documents with query
// TEST: Check permissions persist
$response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $data['databaseId'] . '/collections/' . $data['$id'] . '/documents', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
@@ -4919,6 +4917,37 @@ trait DatabasesBase
'data' => [
'number' => 200
],
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals(10, $response['body']['modified']);
$documents = $this->client->call(Client::METHOD_GET, '/databases/' . $data['databaseId'] . '/collections/' . $data['$id'] . '/documents', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
Query::equal('number', [200])->toString(),
]);
$this->assertEquals(200, $documents['headers']['status-code']);
$this->assertEquals(10, $documents['body']['total']);
foreach ($documents['body']['documents'] as $document) {
$this->assertEquals([
Permission::read(Role::user($this->getUser()['$id'])),
Permission::update(Role::user($this->getUser()['$id'])),
Permission::delete(Role::user($this->getUser()['$id'])),
], $document['$permissions']);
}
// TEST: Update documents with limit
$response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $data['databaseId'] . '/collections/' . $data['$id'] . '/documents', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'data' => [
'number' => 300
],
'queries' => [
Query::limit(5)->toString(),
],
@@ -4943,7 +4972,7 @@ trait DatabasesBase
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'data' => [
'number' => 200
'number' => 300
],
'queries' => [
Query::offset(5)->toString(),
@@ -4957,7 +4986,33 @@ trait DatabasesBase
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'queries' => [Query::equal('number', [200])->toString()]
'queries' => [Query::equal('number', [300])->toString()]
]);
$this->assertEquals(200, $documents['headers']['status-code']);
$this->assertEquals(10, $documents['body']['total']);
// TEST: Update documents with equals filter
$response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $data['databaseId'] . '/collections/' . $data['$id'] . '/documents', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'data' => [
'number' => 400
],
'queries' => [
Query::equal('number', [300])->toString(),
],
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals(10, $response['body']['modified']);
$documents = $this->client->call(Client::METHOD_GET, '/databases/' . $data['databaseId'] . '/collections/' . $data['$id'] . '/documents', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'queries' => [Query::equal('number', [400])->toString()]
]);
$this->assertEquals(200, $documents['headers']['status-code']);
@@ -992,7 +992,8 @@ class DatabasesCustomClientTest extends Scope
'number' => 6,
],
'permissions' => [
Permission::update(Role::user('user2'))
Permission::update(Role::user('user2')),
Permission::read(Role::user($this->getUser()['$id'])),
]
]);
@@ -1012,9 +1013,8 @@ class DatabasesCustomClientTest extends Scope
$documents = $this->client->call(Client::METHOD_GET, '/databases/' . $data['databaseId'] . '/collections/' . $data['$id'] . '/documents', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'x-appwrite-project' => $this->getProject()['$id']
], $this->getHeaders()), [
'queries' => [Query::notEqual('number', 100)->toString()]
]);