1
0
Fork 0
mirror of synced 2024-07-03 21:50:34 +12:00

fix lint issues and remove sleep from test

This commit is contained in:
prateek banga 2023-07-27 02:23:20 +05:30
parent 5c5a8a9115
commit e631f393fc
3 changed files with 24 additions and 35 deletions

View file

@ -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 {
$document = $dbForProject->withRequestTimestamp(

View file

@ -49,7 +49,7 @@
"utopia-php/cache": "0.8.*",
"utopia-php/cli": "0.13.*",
"utopia-php/config": "0.2.*",
"utopia-php/database": "0.38.*",
"utopia-php/database": "0.39.*",
"utopia-php/domains": "1.1.*",
"utopia-php/framework": "0.28.*",
"utopia-php/image": "0.5.*",

View file

@ -320,7 +320,6 @@ class DatabasesCustomClientTest extends Scope
public function testUpdateWithoutRelationPermission(): void
{
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
@ -339,7 +338,6 @@ class DatabasesCustomClientTest extends Scope
$databaseId = $database['body']['$id'];
// Creating collection 1
$collection1 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([
'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
$relation = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collection1['body']['$id'] . '/attributes/relationship', array_merge([
'content-type' => 'application/json',
@ -386,8 +382,6 @@ class DatabasesCustomClientTest extends Scope
'key' => $collection2['body']['$id']
]);
\sleep(2);
$this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collection1['body']['$id'] . '/attributes/string', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
@ -412,8 +406,7 @@ class DatabasesCustomClientTest extends Scope
'default' => null,
]);
\sleep(3);
\sleep(2);
$childDocument = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collection2['body']['$id'] . '/documents', array_merge([
'content-type' => 'application/json',
@ -427,8 +420,6 @@ class DatabasesCustomClientTest extends Scope
'permissions' => [],
]);
\sleep(3);
// 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([
'content-type' => 'application/json',
@ -444,8 +435,6 @@ class DatabasesCustomClientTest extends Scope
]);
$this->assertEquals(201, $parentDocument['headers']['status-code']);
\sleep(3);
// 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
$response = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collection1['body']['$id'] . '/documents/' . $parentDocument['body']['$id'], array_merge([