1
0
Fork 0
mirror of synced 2024-10-05 12:43:13 +13: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,6 +3390,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum
} }
} }
}; };
$skipCheckingPermission = true; $skipCheckingPermission = true;
foreach ($newDocument as $key => $value) { foreach ($newDocument as $key => $value) {
if ($document->getAttribute($key) instanceof Document) { if ($document->getAttribute($key) instanceof Document) {
@ -3404,16 +3405,15 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum
break; break;
} }
} }
if ($skipCheckingPermission) { if ($skipCheckingPermission) {
Authorization::skip( Authorization::skip(
fn() => $checkPermissions($collection, $newDocument, $document, Database::PERMISSION_UPDATE) fn() => $checkPermissions($collection, $newDocument, $document, Database::PERMISSION_UPDATE)
); );
} else { } else {
$checkPermissions($collection, $newDocument, $document, Database::PERMISSION_UPDATE); $checkPermissions($collection, $newDocument, $document, Database::PERMISSION_UPDATE);
;
} }
try { try {
$document = $dbForProject->withRequestTimestamp( $document = $dbForProject->withRequestTimestamp(
$requestTimestamp, $requestTimestamp,

View file

@ -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.*",

View file

@ -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([