fix lint issues and remove sleep from test
This commit is contained in:
parent
5c5a8a9115
commit
e631f393fc
3 changed files with 24 additions and 35 deletions
|
@ -3390,29 +3390,29 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
$skipCheckingPermission = true;
|
|
||||||
foreach ($newDocument as $key => $value) {
|
|
||||||
if ($document->getAttribute($key) instanceof Document) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
//If any of the values are different, we need to check permission.
|
|
||||||
if ($newDocument->getAttribute($key) !== $value) {
|
|
||||||
$skipCheckingPermission = false;
|
|
||||||
$newDocument->removeAttribute('$collectionId');
|
|
||||||
$newDocument->removeAttribute('$databaseId');
|
|
||||||
$newDocument->setAttribute('$collection', $collection->getId());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($skipCheckingPermission) {
|
|
||||||
Authorization::skip(
|
|
||||||
fn() => $checkPermissions($collection, $newDocument, $document, Database::PERMISSION_UPDATE)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$checkPermissions($collection, $newDocument, $document, Database::PERMISSION_UPDATE);
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
$skipCheckingPermission = true;
|
||||||
|
foreach ($newDocument as $key => $value) {
|
||||||
|
if ($document->getAttribute($key) instanceof Document) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//If any of the values are different, we need to check permission.
|
||||||
|
if ($newDocument->getAttribute($key) !== $value) {
|
||||||
|
$skipCheckingPermission = false;
|
||||||
|
$newDocument->removeAttribute('$collectionId');
|
||||||
|
$newDocument->removeAttribute('$databaseId');
|
||||||
|
$newDocument->setAttribute('$collection', $collection->getId());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($skipCheckingPermission) {
|
||||||
|
Authorization::skip(
|
||||||
|
fn() => $checkPermissions($collection, $newDocument, $document, Database::PERMISSION_UPDATE)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$checkPermissions($collection, $newDocument, $document, Database::PERMISSION_UPDATE);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$document = $dbForProject->withRequestTimestamp(
|
$document = $dbForProject->withRequestTimestamp(
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
"utopia-php/cache": "0.8.*",
|
"utopia-php/cache": "0.8.*",
|
||||||
"utopia-php/cli": "0.13.*",
|
"utopia-php/cli": "0.13.*",
|
||||||
"utopia-php/config": "0.2.*",
|
"utopia-php/config": "0.2.*",
|
||||||
"utopia-php/database": "0.38.*",
|
"utopia-php/database": "0.39.*",
|
||||||
"utopia-php/domains": "1.1.*",
|
"utopia-php/domains": "1.1.*",
|
||||||
"utopia-php/framework": "0.28.*",
|
"utopia-php/framework": "0.28.*",
|
||||||
"utopia-php/image": "0.5.*",
|
"utopia-php/image": "0.5.*",
|
||||||
|
|
|
@ -320,7 +320,6 @@ class DatabasesCustomClientTest extends Scope
|
||||||
|
|
||||||
public function testUpdateWithoutRelationPermission(): void
|
public function testUpdateWithoutRelationPermission(): void
|
||||||
{
|
{
|
||||||
|
|
||||||
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
@ -339,7 +338,6 @@ class DatabasesCustomClientTest extends Scope
|
||||||
|
|
||||||
$databaseId = $database['body']['$id'];
|
$databaseId = $database['body']['$id'];
|
||||||
|
|
||||||
|
|
||||||
// Creating collection 1
|
// Creating collection 1
|
||||||
$collection1 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([
|
$collection1 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
|
@ -371,8 +369,6 @@ class DatabasesCustomClientTest extends Scope
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
\sleep(2);
|
|
||||||
|
|
||||||
// Creating one to many relationship from collection 1 to colletion 2
|
// Creating one to many relationship from collection 1 to colletion 2
|
||||||
$relation = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collection1['body']['$id'] . '/attributes/relationship', array_merge([
|
$relation = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collection1['body']['$id'] . '/attributes/relationship', array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
|
@ -386,8 +382,6 @@ class DatabasesCustomClientTest extends Scope
|
||||||
'key' => $collection2['body']['$id']
|
'key' => $collection2['body']['$id']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
\sleep(2);
|
|
||||||
|
|
||||||
$this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collection1['body']['$id'] . '/attributes/string', array_merge([
|
$this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collection1['body']['$id'] . '/attributes/string', array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
@ -412,8 +406,7 @@ class DatabasesCustomClientTest extends Scope
|
||||||
'default' => null,
|
'default' => null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
\sleep(3);
|
\sleep(2);
|
||||||
|
|
||||||
|
|
||||||
$childDocument = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collection2['body']['$id'] . '/documents', array_merge([
|
$childDocument = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collection2['body']['$id'] . '/documents', array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
|
@ -427,8 +420,6 @@ class DatabasesCustomClientTest extends Scope
|
||||||
'permissions' => [],
|
'permissions' => [],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
\sleep(3);
|
|
||||||
|
|
||||||
// Creating parent document with a child reference to test the permissions
|
// Creating parent document with a child reference to test the permissions
|
||||||
$parentDocument = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collection1['body']['$id'] . '/documents', array_merge([
|
$parentDocument = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collection1['body']['$id'] . '/documents', array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
|
@ -444,8 +435,6 @@ class DatabasesCustomClientTest extends Scope
|
||||||
]);
|
]);
|
||||||
$this->assertEquals(201, $parentDocument['headers']['status-code']);
|
$this->assertEquals(201, $parentDocument['headers']['status-code']);
|
||||||
|
|
||||||
\sleep(3);
|
|
||||||
|
|
||||||
// Update document
|
// Update document
|
||||||
// This is the point of this test. We should be allowed to do this action, and it should not fail on permission check
|
// This is the point of this test. We should be allowed to do this action, and it should not fail on permission check
|
||||||
$response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collection1['body']['$id'] . '/documents/' . $parentDocument['body']['$id'], array_merge([
|
$response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collection1['body']['$id'] . '/documents/' . $parentDocument['body']['$id'], array_merge([
|
||||||
|
|
Loading…
Reference in a new issue