From c59887e8fb26326e96ffed847cc19dfe79ab6be3 Mon Sep 17 00:00:00 2001 From: prateek banga Date: Fri, 25 Aug 2023 15:55:04 +0530 Subject: [PATCH] fixes issue in sub queries --- app/config/collections.php | 22 ++------------------ app/init.php | 22 +------------------- tests/e2e/Services/Users/UsersBase.php | 28 ++++++++++---------------- 3 files changed, 14 insertions(+), 58 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index f066c38c70..d7f6a6601c 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -1673,7 +1673,7 @@ $commonCollections = [ 'required' => false, 'default' => null, 'array' => true, - 'filters' => ['subQueryTargets'], + 'filters' => ['subQueryTopicTargets'], ] ], 'indexes' => [ @@ -1861,17 +1861,6 @@ $commonCollections = [ 'array' => false, 'filters' => [], ], - [ - '$id' => ID::custom('topics'), - 'type' => Database::VAR_STRING, - 'format' => '', - 'size' => 16384, - 'signed' => true, - 'required' => false, - 'default' => null, - 'array' => true, - 'filters' => ['subQueryTopics'], - ] ], 'indexes' => [ [ @@ -1901,14 +1890,7 @@ $commonCollections = [ 'attributes' => ['providerInternalId'], 'lengths' => [], 'orders' => [], - ], - [ - '$id' => ID::custom('_key_providerType'), - 'type' => Database::INDEX_KEY, - 'attributes' => ['providerType'], - 'lengths' => [], - 'orders' => [], - ], + ] ], ], ]; diff --git a/app/init.php b/app/init.php index 57d99dac83..eed61f2eeb 100644 --- a/app/init.php +++ b/app/init.php @@ -555,29 +555,9 @@ Database::addFilter( } ); -Database::addFilter( - 'subQueryTopics', - function (mixed $value) { - return null; - }, - function (mixed $value, Document $document, Database $database) { - $topicIds = Authorization::skip(fn () => \array_map( - fn ($document) => $document->getAttribute('topicId'), - $database - ->find('subscribers', [ - Query::equal('targetInternalId', [$document->getInternalId()]), - Query::limit(APP_LIMIT_SUBQUERY), - ]) - )); - if (\count($topicIds) > 0) { - return $database->find('topics', [Query::equal('$id', $topicIds)]); - } - return []; - } -); Database::addFilter( - 'subQueryTargets', + 'subQueryTopicTargets', function (mixed $value) { return null; }, diff --git a/tests/e2e/Services/Users/UsersBase.php b/tests/e2e/Services/Users/UsersBase.php index 947a3a5cd9..923eb35adf 100644 --- a/tests/e2e/Services/Users/UsersBase.php +++ b/tests/e2e/Services/Users/UsersBase.php @@ -1216,11 +1216,11 @@ trait UsersBase */ public function testCreateUserTarget(array $data): array { - $provider = $this->client->call(Client::METHOD_POST, '/messaging/providers/sendgrid', [ + $provider = $this->client->call(Client::METHOD_POST, '/messaging/providers/sendgrid', \array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ], [ + ], $this->getHeaders()), [ + 'providerId' => 'unique()', 'name' => 'Sengrid1', 'apiKey' => 'my-apikey' ]); @@ -1228,8 +1228,7 @@ trait UsersBase $response = $this->client->call(Client::METHOD_POST, '/users/' . $data['userId'] . '/targets', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ]), [ + ], $this->getHeaders()), [ 'targetId' => ID::unique(), 'providerId' => $provider['body']['$id'], 'identifier' => 'my-token', @@ -1248,8 +1247,7 @@ trait UsersBase $response = $this->client->call(Client::METHOD_PATCH, '/users/' . $data['userId'] . '/targets/' . $data['$id'] . '/identifier', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ]), [ + ], $this->getHeaders()), [ 'identifier' => 'my-updated-token', ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -1258,17 +1256,16 @@ trait UsersBase } /** - * @depends testGetUser + * @depends testUpdateUserTarget */ public function testListUserTarget(array $data) { $response = $this->client->call(Client::METHOD_GET, '/users/' . $data['userId'] . '/targets', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ])); + ], $this->getHeaders())); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(1, $response['body']['total']); + $this->assertEquals(1, \count($response['body']['targets'])); } /** @@ -1279,8 +1276,7 @@ trait UsersBase $response = $this->client->call(Client::METHOD_GET, '/users/' . $data['userId'] . '/targets/' . $data['$id'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ])); + ], $this->getHeaders())); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals($data['$id'], $response['body']['$id']); } @@ -1293,14 +1289,12 @@ trait UsersBase $response = $this->client->call(Client::METHOD_DELETE, '/users/' . $data['userId'] . '/targets/' . $data['$id'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ])); + ], $this->getHeaders())); $this->assertEquals(204, $response['headers']['status-code']); $response = $this->client->call(Client::METHOD_GET, '/users/' . $data['userId'] . '/targets', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ])); + ], $this->getHeaders())); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(0, $response['body']['total']); }